Merge pull request #4 from kemitix/codacy-clean-up

Codacy clean up
This commit is contained in:
Paul Campbell 2017-09-19 06:38:46 +01:00 committed by GitHub
commit 732c4f5206
5 changed files with 19 additions and 11 deletions

View file

@ -33,7 +33,7 @@ class Address {
private final String street; private final String street;
String getStreet() { protected String getStreet() {
return street; return street;
} }
} }

View file

@ -33,7 +33,7 @@ class Customer {
private final Address address; private final Address address;
Address getAddress() { protected Address getAddress() {
return address; return address;
} }

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));
}
} }

View file

@ -60,7 +60,7 @@ public class TypeAliasTest {
//given //given
final String value = "value"; final String value = "value";
final AnAlias anAlias = AnAlias.of(value); final AnAlias anAlias = AnAlias.of(value);
assertThat(anAlias.toString()).isEqualTo(value.toString()); assertThat(anAlias.toString()).isEqualTo(value);
} }
private static class AnAlias extends TypeAlias<String> { private static class AnAlias extends TypeAlias<String> {
@ -74,7 +74,7 @@ public class TypeAliasTest {
super(value); super(value);
} }
static AnAlias of(final String value) { protected static AnAlias of(final String value) {
return new AnAlias(value); return new AnAlias(value);
} }
} }