{Identity,Mon}Test: JUnit tests should include asserts

This commit is contained in:
Paul Campbell 2017-09-18 20:40:53 +01:00
parent 141d508138
commit b3c6520067
2 changed files with 15 additions and 7 deletions

View file

@ -17,7 +17,7 @@ public class IdentityTest implements WithAssertions {
//when //when
final Identity<Integer> idInt = idString.map(String::length); final Identity<Integer> idInt = idString.map(String::length);
//then //then
idInt.map(id -> assertThat(id).isEqualTo(3)); assertIdentityContains(idInt, 3);
} }
@Test @Test
@ -31,7 +31,11 @@ public class IdentityTest implements WithAssertions {
.map(String::toLowerCase) .map(String::toLowerCase)
.map(String::getBytes); .map(String::getBytes);
//then //then
idBytes.map(bytes -> assertThat(bytes).isEqualTo("par".getBytes())); assertIdentityContains(idBytes, "par".getBytes());
}
private <T> void assertIdentityContains(final Identity<T> identity, final T expected) {
identity.map(id -> assertThat(id).isEqualTo(expected));
} }
} }

View file

@ -15,7 +15,7 @@ public class MonTest {
//when //when
final Mon<String> wrap = Mon.of("test"); final Mon<String> wrap = Mon.of("test");
//then //then
wrap.map(value -> assertThat(value).isEqualTo("test")); assertMonContains(wrap, "test");
} }
@Test @Test
@ -25,7 +25,7 @@ public class MonTest {
//when //when
final Mon<String> updated = wrap.map(a -> a + " more"); final Mon<String> updated = wrap.map(a -> a + " more");
//then //then
updated.map(value -> assertThat(value).isEqualTo("test more")); assertMonContains(updated, "test more");
} }
@Test @Test
@ -35,7 +35,7 @@ public class MonTest {
//when //when
final Mon<Integer> result = wrap.map(String::length); final Mon<Integer> result = wrap.map(String::length);
//then //then
result.map(value -> assertThat(value).isEqualTo(4)); assertMonContains(result, 4);
} }
@Test @Test
@ -52,7 +52,7 @@ public class MonTest {
final Optional<Mon<String>> longAndInvalid = factory.apply("value is too long"); final Optional<Mon<String>> longAndInvalid = factory.apply("value is too long");
//then //then
assertThat(shortAndValid).isNotEmpty(); assertThat(shortAndValid).isNotEmpty();
shortAndValid.ifPresent(valid -> valid.map(value -> assertThat(value).contains("value okay"))); shortAndValid.ifPresent(valid -> assertMonContains(valid, "value okay"));
assertThat(longAndInvalid).isEmpty(); assertThat(longAndInvalid).isEmpty();
} }
@ -76,7 +76,7 @@ public class MonTest {
final Mon<Mon<String>> nonFlatMapped = wrap.map(Mon::of); final Mon<Mon<String>> nonFlatMapped = wrap.map(Mon::of);
final Mon<String> result = wrap.flatMap(Mon::of); final Mon<String> result = wrap.flatMap(Mon::of);
//then //then
result.map(value -> assertThat(value).isEqualTo("test")); assertMonContains(result, "test");
nonFlatMapped.map(inner -> assertThat(result).isEqualTo(inner)); nonFlatMapped.map(inner -> assertThat(result).isEqualTo(inner));
} }
@ -144,4 +144,8 @@ public class MonTest {
assertThat(one).isNotEqualTo(notAMon); assertThat(one).isNotEqualTo(notAMon);
assertThat(one).isNotEqualTo(null); assertThat(one).isNotEqualTo(null);
} }
private <T> void assertMonContains(final Mon<T> wrap, final T expected) {
wrap.map(value -> assertThat(value).isEqualTo(expected));
}
} }