Update and clarify TypeAlias tests

This commit is contained in:
Paul Campbell 2017-12-09 17:35:18 +00:00
parent 3c2b7dd5a1
commit 27019b23c1

View file

@ -1,9 +1,11 @@
package net.kemitix.mon; package net.kemitix.mon;
import org.assertj.core.util.Strings;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.function.Function; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -16,7 +18,7 @@ public class TypeAliasTest {
//when //when
final TypeAlias<String> typeAlias = givenTypeAlias(value); final TypeAlias<String> typeAlias = givenTypeAlias(value);
//then //then
assertThat(typeAlias.<Boolean>map(value::equals)).isTrue(); assertThat(typeAlias.getValue()).isSameAs(value);
} }
private TypeAlias<String> givenTypeAlias(final String value) { private TypeAlias<String> givenTypeAlias(final String value) {
@ -33,17 +35,17 @@ public class TypeAliasTest {
new TypeAlias<Iterable<String>>(iterable) { new TypeAlias<Iterable<String>>(iterable) {
}; };
//then //then
assertThat(typeAlias.<Boolean>map(iterable::equals)).isTrue(); assertThat(typeAlias.getValue()).isSameAs(iterable);
} }
@Test @Test
public void shouldCreateAnAliasedTypeAndGetTheValue() { public void shouldCreateATypeAliasSubclassAndGetTheValue() {
//given //given
final String value = "value"; final String value = "value";
//when //when
final AnAlias anAlias = AnAlias.of(value); final AnAlias anAlias = AnAlias.of(value);
//then //then
assertThat(anAlias.<Boolean>map(value::equals)).isTrue(); assertThat(anAlias.getValue()).isSameAs(value);
} }
@Test @Test
@ -67,7 +69,7 @@ public class TypeAliasTest {
} }
@Test @Test
public void shouldBeEqualToUnAliasedValue() { public void shouldBeEqualToRawValue() {
//given //given
final String value = "value"; final String value = "value";
final AnAlias anAlias = AnAlias.of(value); final AnAlias anAlias = AnAlias.of(value);
@ -87,22 +89,22 @@ public class TypeAliasTest {
@Test @Test
public void shouldHaveSameToStringAsAliasedType() { public void shouldHaveSameToStringAsAliasedType() {
//given //given
final String value = "value"; final List<Integer> value = Arrays.asList(1, 2, 3);
//when //when
final AnAlias anAlias = AnAlias.of(value); final TypeAlias<List<Integer>> anAlias = new TypeAlias<List<Integer>>(value) {
};
//then //then
assertThat(anAlias.toString()).isEqualTo(value); assertThat(anAlias.toString()).isEqualTo(value.toString());
} }
@Test @Test
public void shouldMapTypeAlias() { public void shouldMapTypeAlias() {
//given //given
final AnAlias anAlias = AnAlias.of("text"); final AnAlias anAlias = AnAlias.of("text");
final Function<String, String> function = v -> v;
//when //when
final String value = anAlias.map(function); final String value = anAlias.map(Strings::quote);
//then //then
assertThat(value).isEqualTo("text"); assertThat(value).isEqualTo("'text'");
} }
private static class AnAlias extends TypeAlias<String> { private static class AnAlias extends TypeAlias<String> {