diff --git a/sass-embedded-host/build.gradle b/sass-embedded-host/build.gradle index 5a74f1a3..6c8d45fb 100644 --- a/sass-embedded-host/build.gradle +++ b/sass-embedded-host/build.gradle @@ -42,6 +42,7 @@ dependencies { sassEmbedded "sass:sass_embedded:$dartSassVersion:windows-ia32@zip" sassEmbedded "sass:sass_embedded:$dartSassVersion:windows-x64@zip" + testImplementation 'org.springframework:spring-core:5.3.7' testImplementation 'org.slf4j:slf4j-simple:1.7.30' testRuntimeOnly 'org.webjars:webjars-locator:0.30' testRuntimeOnly 'org.webjars:bootstrap:4.6.0' diff --git a/sass-embedded-host/src/main/java/de/larsgrefer/sass/embedded/functions/ConversionService.java b/sass-embedded-host/src/main/java/de/larsgrefer/sass/embedded/functions/ConversionService.java index 3051cbce..800659bd 100644 --- a/sass-embedded-host/src/main/java/de/larsgrefer/sass/embedded/functions/ConversionService.java +++ b/sass-embedded-host/src/main/java/de/larsgrefer/sass/embedded/functions/ConversionService.java @@ -263,7 +263,7 @@ else if (targetType.isAssignableFrom(Map.class)) { Map collect = sassMap.getEntriesList() .stream() .collect(Collectors.toMap( - sassEntry -> toJavaValue(sassEntry.getValue(), keyClass, keyType), + sassEntry -> toJavaValue(sassEntry.getKey(), keyClass, keyType), sassEntry -> toJavaValue(sassEntry.getValue(), valueClass, valueType) )); diff --git a/sass-embedded-host/src/test/java/de/larsgrefer/sass/embedded/functions/ConversionServiceTest.java b/sass-embedded-host/src/test/java/de/larsgrefer/sass/embedded/functions/ConversionServiceTest.java index 02bde62a..4bb3b3e5 100644 --- a/sass-embedded-host/src/test/java/de/larsgrefer/sass/embedded/functions/ConversionServiceTest.java +++ b/sass-embedded-host/src/test/java/de/larsgrefer/sass/embedded/functions/ConversionServiceTest.java @@ -1,14 +1,20 @@ package de.larsgrefer.sass.embedded.functions; import org.junit.jupiter.api.Test; +import org.springframework.core.ParameterizedTypeReference; import sass.embedded_protocol.EmbeddedSass; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; +import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.in; class ConversionServiceTest { @@ -137,5 +143,33 @@ void listConversion() { assertThat(sassList.getContentsCount()).isEqualTo(stringList.size()); assertThat(sassList.getContentsList()).allMatch(v -> v.getValueCase().equals(EmbeddedSass.Value.ValueCase.STRING)); + + Type listType = new ParameterizedTypeReference>() { + }.getType(); + List list = ConversionService.toJavaValue(value, List.class, listType); + + assertThat(list).containsExactly("foo", "bar"); + } + + @Test + void mapConverstion() { + Map intMap = new HashMap<>(); + intMap.put("foo", 1); + intMap.put("bar", 2); + + EmbeddedSass.Value value = ConversionService.toSassValue(intMap); + + assertThat(value.getValueCase()).isEqualTo(EmbeddedSass.Value.ValueCase.MAP); + + EmbeddedSass.Value.Map sassMap = value.getMap(); + + assertThat(sassMap.getEntriesCount()).isEqualTo(2); + + Type mapType = new ParameterizedTypeReference>() { + }.getType(); + Map map = ConversionService.toJavaValue(value, Map.class, mapType); + + assertThat(map).containsEntry("foo", 1); + assertThat(map).containsEntry("bar", 2); } } \ No newline at end of file