Skip to content

Commit

Permalink
Code cleanup and minor test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-costigliola committed Nov 6, 2020
1 parent c11e82f commit 41a6c42
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void then_char() {
then('z').isGreaterThan('a');
}

@SuppressWarnings("deprecation")
@Test
void then_Character() {
then(new Character('A')).isEqualTo(new Character('A'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.assertj.core.api.assumptions.BaseAssumptionRunner.assumptionRunner;

import java.util.stream.Stream;

import org.assertj.core.api.ClassAssert;
import org.assertj.core.api.ClassAssertBaseTest.AnnotatedClass;
import org.assertj.core.api.ClassAssertBaseTest.AnotherAnnotation;
import org.assertj.core.api.ClassAssertBaseTest.MyAnnotation;
import org.assertj.core.api.ProxyableClassAssert;
import org.assertj.core.util.VisibleForTesting;

import java.util.stream.Stream;

/**
* verify that assertions final methods in {@link ClassAssert} work with assumptions (i.e. that they are proxied correctly in {@link ProxyableClassAssert}).
*/
class Class_final_method_assertions_in_assumptions_Test extends BaseAssumptionsRunnerTest {

@SuppressWarnings("unchecked")
public static Stream<AssumptionRunner<?>> provideAssumptionsRunners() {
return Stream.of(
assumptionRunner(AnnotatedClass.class,
value -> assumeThat(value).hasAnnotations(MyAnnotation.class, AnotherAnnotation.class),
value -> assumeThat(value).hasAnnotations(SafeVarargs.class, VisibleForTesting.class))
);
return Stream.of(assumptionRunner(AnnotatedClass.class,
value -> assumeThat(value).hasAnnotations(MyAnnotation.class, AnotherAnnotation.class),
value -> assumeThat(value).hasAnnotations(SafeVarargs.class, VisibleForTesting.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
class Map_special_assertion_methods_in_assumptions_Test extends BaseAssumptionsRunnerTest {

@SuppressWarnings("unchecked")
public static Stream<AssumptionRunner<?>> provideAssumptionsRunners() {

List<String> names = asList("Dave", "Jeff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public static Stream<AssumptionRunner<?>> provideAssumptionsRunners() {
.containsAnyOf(bart, lisa),
value -> assumeThat(value).flatExtracting("children")
.containsAnyOf(homer, fred)),
assumptionRunner(array(homer, fred),
value -> assumeThat(value).flatExtracting(childrenExtractor)
.containsAnyOf(bart, lisa),
value -> assumeThat(value).flatExtracting(childrenExtractor)
.containsAnyOf(homer, fred)),
assumptionRunner(array(homer, fred),
value -> assumeThat(value).flatExtracting(CartoonCharacter::getChildren)
.containsAnyOf(bart, lisa),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
*/
class Predicate_final_method_assertions_in_assumptions_Test extends BaseAssumptionsRunnerTest {

@SuppressWarnings("unchecked")
public static Stream<AssumptionRunner<?>> provideAssumptionsRunners() {
Predicate<MapEntry<String, String>> ballSportPredicate = sport -> sport.value.contains("ball");
return Stream.of(
assumptionRunner(ballSportPredicate,
value -> assumeThat(value).accepts(entry("sport", "football"), entry("sport", "basketball")),
value -> assumeThat(value).accepts(entry("sport", "boxing"), entry("sport", "marathon"))),
assumptionRunner(ballSportPredicate,
value -> assumeThat(value).rejects(entry("sport", "boxing"), entry("sport", "marathon")),
value -> assumeThat(value).rejects(entry("sport", "football"), entry("sport", "basketball")))
);
return Stream.of(assumptionRunner(ballSportPredicate,
value -> assumeThat(value).accepts(entry("sport", "football"),
entry("sport", "basketball")),
value -> assumeThat(value).accepts(entry("sport", "boxing"), entry("sport", "marathon"))),
assumptionRunner(ballSportPredicate,
value -> assumeThat(value).rejects(entry("sport", "boxing"), entry("sport", "marathon")),
value -> assumeThat(value).rejects(entry("sport", "football"),
entry("sport", "basketball"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<CartoonCharacter> extract(CartoonCharacter input) {
private final ThrowingExtractor<CartoonCharacter, List<CartoonCharacter>, Exception> throwingExtractor = new ThrowingExtractor<CartoonCharacter, List<CartoonCharacter>, Exception>() {
@Override
public List<CartoonCharacter> extractThrows(CartoonCharacter cartoonCharacter) throws Exception {
if (cartoonCharacter.getChildren().isEmpty()) { throw new Exception("no children"); }
if (cartoonCharacter.getChildren().isEmpty()) throw new Exception("no children");
return cartoonCharacter.getChildren();
}
};
Expand Down Expand Up @@ -108,12 +108,12 @@ void should_allow_assertions_on_empty_result_lists() {
}

@Test
void should_throw_null_pointer_exception_when_extracting_from_null_with_extractor() {
void should_bubble_up_null_pointer_exception_from_extractor() {
assertThatNullPointerException().isThrownBy(() -> assertThat(newArrayList(homer, null)).flatExtracting(childrenExtractor));
}

@Test
void should_throw_null_pointer_exception_when_extracting_from_null() {
void should_bubble_up_null_pointer_exception_from_lambda_extractor() {
assertThatNullPointerException().isThrownBy(() -> assertThat(newArrayList(homer, null)).flatExtracting(children));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ void should_allow_assertions_on_empty_result_lists() {
}

@Test
void should_throw_null_pointer_exception_when_extracting_from_null_with_extractor() {
assertThatNullPointerException().isThrownBy(() -> assertThat(newSortedSet(homer, null)).flatExtracting(childrenExtractor));
void should_bubble_up_null_pointer_exception_from_extractor() {
// GIVEN
SortedSet<CartoonCharacter> setWithNullElements = newSortedSet(homer, null);
// WHEN THEN
assertThatNullPointerException().isThrownBy(() -> assertThat(setWithNullElements).flatExtracting(childrenExtractor));
}

@Test
void should_throw_null_pointer_exception_when_extracting_from_null() {
assertThatNullPointerException().isThrownBy(() -> assertThat(newSortedSet(homer, null)).flatExtracting(children));
void should_bubble_up_null_pointer_exception_from_lambda_extractor() {
// GIVEN
SortedSet<CartoonCharacter> setWithNullElements = newSortedSet(homer, null);
// WHEN THEN
assertThatNullPointerException().isThrownBy(() -> assertThat(setWithNullElements).flatExtracting(children));
}

@Test
Expand Down Expand Up @@ -235,7 +241,6 @@ void flatExtracting_should_keep_assertion_state_with_extractor() {
assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);
}


@Test
void flatExtracting_should_keep_assertion_state() {
// GIVEN
Expand Down Expand Up @@ -289,7 +294,7 @@ void flatExtracting_with_ThrowingExtractor_should_keep_assertion_state() {
}

private static SortedSet<CartoonCharacter> newSortedSet(CartoonCharacter... cartoonCharacters) {
TreeSet<CartoonCharacter> cartoonCharacterSortedSet = new TreeSet<>(comparing(CartoonCharacter::getName));
TreeSet<CartoonCharacter> cartoonCharacterSortedSet = new TreeSet<>(comparing(t -> t == null ? "" : t.getName()));
for (CartoonCharacter cartoonCharacter : cartoonCharacters) {
cartoonCharacterSortedSet.add(cartoonCharacter);
}
Expand Down

0 comments on commit 41a6c42

Please sign in to comment.