Merge pull request #26 from kemitix/jdk-9-compatible

Compile with Java 9 Compatibility
This commit is contained in:
Paul Campbell 2018-03-04 10:10:15 +00:00 committed by GitHub
commit b4d42447dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 12 deletions

View file

@ -30,6 +30,13 @@ pipeline {
}
}
}
stage('Java 9') {
steps {
withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') {
sh 'mvn clean install'
}
}
}
}
}
stage('Test Results') {

View file

@ -10,6 +10,7 @@
<version>5.1.0</version>
<relativePath/>
</parent>
<groupId>net.kemitix</groupId>
<artifactId>mon</artifactId>
<version>0.6.0-SNAPSHOT</version>

View file

@ -118,17 +118,8 @@ public class Mon<T> implements Functor<T, Mon<?>> {
* @return true if they are the same
*/
@Override
@SuppressWarnings("npathcomplexity")
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Mon<?> mon = (Mon<?>) o;
return value.equals(mon.value);
return this == o || o != null && getClass() == o.getClass() && value.equals(((Mon<?>) o).value);
}
}

View file

@ -93,6 +93,7 @@ public class MonTest {
}
@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void factoryRequiresValidator() {
assertThatNullPointerException().isThrownBy(
() -> Mon.factory(null, Optional::of, Optional::empty))
@ -100,6 +101,7 @@ public class MonTest {
}
@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void factoryRequiresOnValid() {
assertThatNullPointerException().isThrownBy(
() -> Mon.factory(v -> true, null, Optional::empty))
@ -107,12 +109,27 @@ public class MonTest {
}
@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void factoryRequiresOnInvalid() {
assertThatNullPointerException().isThrownBy(
() -> Mon.factory(v -> true, Optional::of, null))
.withMessage("onInvalid");
}
@Test
public void factory() {
//given
final Function<Integer, Optional<?>> evenMonFactory =
Mon.factory((Integer v) -> v % 2 == 0, Optional::of, Optional::empty);
//when
final Optional<?> oddResult = evenMonFactory.apply(1);
final Optional<?> evenResult = evenMonFactory.apply(2);
//then
assertThat(oddResult).isEmpty();// because 1 % 2 != 0
assertThat(evenResult).isNotEmpty(); // because 2 % 2 == 0
evenResult.ifPresent(value -> assertThat(value).isEqualTo(Mon.of(2)));
}
@Test
public void shouldGetInvalidResultWhenFactoryApplyWithNull() {
//given

View file

@ -92,7 +92,7 @@ public class TypeAliasTest {
final String value = "value";
final AnAlias anAlias = AnAlias.of(value);
//then
assertThat(anAlias.hashCode()).isEqualTo(value.hashCode());
assertThat(anAlias).hasSameHashCodeAs(value);
}
@Test