Skip to content

Commit

Permalink
Add more Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgrefer committed May 13, 2021
1 parent d0d7c1f commit 9b41296
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions sass-embedded-host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<List<String>>() {
}.getType();
List<String> list = ConversionService.toJavaValue(value, List.class, listType);

assertThat(list).containsExactly("foo", "bar");
}

@Test
void mapConverstion() {
Map<String, Integer> 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<Map<String, Integer>>() {
}.getType();
Map<String, Integer> map = ConversionService.toJavaValue(value, Map.class, mapType);

assertThat(map).containsEntry("foo", 1);
assertThat(map).containsEntry("bar", 2);
}
}

0 comments on commit 9b41296

Please sign in to comment.