Skip to content

Commit

Permalink
- Disabled: coveralls for Travis (now it's done by Semaphore)
Browse files Browse the repository at this point in the history
- Functions.useIfSatisfy is removed in favor of Java8's Optional
  • Loading branch information
kevin-lee committed Jun 10, 2015
1 parent 62b7aa6 commit d857252
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ script:
- mvn clean test package
- gradle clean test jar

after_success:
- gradle jacocoTestReport coveralls
#after_success:
# - gradle jacocoTestReport coveralls
19 changes: 0 additions & 19 deletions src/main/java/cc/kevinlee/functional/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,4 @@ public static <O, T, T2, T3, T4, T5, T6, T7, T8, T9> Consumer<O> accepting(final
}
/* @formatter:on */

/**
* Conditionally uses the given type. So it returns the given value T if the given predicated is satisfied.
* Otherwise it uses the value returned from the given Supplier.
*
* @param value the given value which might be used.
* @param predicate the predicate to be satisfied.
* @param otherwise Supplier to get the alternative value.
* @param <T> the given value type.
* @return the given value of type T if the predicate is satisfied. Otherwise the value from the Supplier.
*/
public static <T> T useIfSatisfy(T value, Predicate<T> predicate, Supplier<T> otherwise) {
/* @formatter:off */
Objects.requireNonNull(predicate, "The predicate must not be null.");
Objects.requireNonNull(otherwise, "The alternative supplier must not be null.");
return predicate.test(value) ?
value :
otherwise.get();
/* @formatter:on */
}
}
60 changes: 0 additions & 60 deletions src/test/java/cc/kevinlee/functional/FunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2255,64 +2255,4 @@ public void testAccepting9WithStream() {
verify(testBean3, times(1)).run(param1, param2, param3, param4, param5, param6, param7, param8, param9);
}

@Test
public void testUseItIfSatisfyWithNullPredicate() {
/* Given */
final Integer num1 = 5;
final Integer expected = 5;

test("Test useItIfSatisfy1", "useIfSatisfy should throw NullPointerException when null predicate is given.")
.when(
() -> useIfSatisfy(num1, null, () -> 1)
)
.expect(throwing(NullPointerException.class)
.containsMessage("predicate must not be null")
);
}

@Test
public void testUseItIfSatisfyWithNullAlternativeSupplier() {
/* Given */
final Integer num1 = 5;
final Integer expected = 5;

test("Test useItIfSatisfy1", "useIfSatisfy should throw NullPointerException when the alternative supplier is null.")
.when(
() -> useIfSatisfy(num1, i -> i > 0, null)
)
.expect(throwing(NullPointerException.class)
.containsMessage("alternative supplier must not be null")
);
}

@Test
public void testUseItIfSatisfy() {
/* Given */
final Integer num1 = 5;
final Integer expected = 5;

test("Test useItIfSatisfy1", "useIfSatisfy with predicate satisfied")
.when(
() -> useIfSatisfy(num1, i -> i > 0, () -> 1)
)
.then(
actual -> assertThat(actual).isEqualTo(expected)
);
}

@Test
public void testUseItIfSatisfy2() {
/* Given */
final Integer num1 = 5;
final Integer expected = -1;
final Integer alternative = expected;

test("Test useItIfSatisfy1", "useIfSatisfy with predicate not satisfied")
.when(
() -> useIfSatisfy(num1, i -> i < 0, () -> alternative)
)
.then(
actual -> assertThat(actual).isEqualTo(expected)
);
}
}

0 comments on commit d857252

Please sign in to comment.