Search in sources :

Example 1 with ThrowingExtractor

use of org.assertj.core.api.iterable.ThrowingExtractor in project assertj-core by joel-costigliola.

the class AtomicReferenceArrayAssert_flatExtracting_Test method should_allow_assertions_on_joined_lists_when_extracting_children_with_anonymous_class_throwing_extractor.

@Test
public void should_allow_assertions_on_joined_lists_when_extracting_children_with_anonymous_class_throwing_extractor() {
    AtomicReferenceArray<CartoonCharacter> cartoonCharacters = new AtomicReferenceArray<>(array(homer, fred));
    assertThat(cartoonCharacters).flatExtracting(new ThrowingExtractor<CartoonCharacter, List<CartoonCharacter>, Exception>() {

        @Override
        public List<CartoonCharacter> extractThrows(CartoonCharacter cartoonCharacter) throws Exception {
            if (cartoonCharacter.getChildren().isEmpty())
                throw new Exception("no children");
            return cartoonCharacter.getChildren();
        }
    }).containsOnly(bart, lisa, maggie, pebbles);
}
Also used : CartoonCharacter(org.assertj.core.test.CartoonCharacter) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) ThrowingExtractor(org.assertj.core.api.iterable.ThrowingExtractor) ExpectedException(org.assertj.core.test.ExpectedException) Test(org.junit.Test)

Example 2 with ThrowingExtractor

use of org.assertj.core.api.iterable.ThrowingExtractor in project assertj-core by joel-costigliola.

the class ObjectArrayAssert_flatExtracting_Test method should_allow_assertions_on_joined_lists_when_extracting_children_with_anonymous_class_throwing_extractor.

@Test
public void should_allow_assertions_on_joined_lists_when_extracting_children_with_anonymous_class_throwing_extractor() {
    CartoonCharacter[] cartoonCharacters = array(homer, fred);
    assertThat(cartoonCharacters).flatExtracting(new ThrowingExtractor<CartoonCharacter, List<CartoonCharacter>, Exception>() {

        @Override
        public List<CartoonCharacter> extractThrows(CartoonCharacter cartoonCharacter) throws Exception {
            if (cartoonCharacter.getChildren().isEmpty())
                throw new Exception("no children");
            return cartoonCharacter.getChildren();
        }
    }).containsOnly(bart, lisa, maggie, pebbles);
}
Also used : CartoonCharacter(org.assertj.core.test.CartoonCharacter) ThrowingExtractor(org.assertj.core.api.iterable.ThrowingExtractor) ExpectedException(org.assertj.core.test.ExpectedException) Test(org.junit.Test)

Aggregations

ThrowingExtractor (org.assertj.core.api.iterable.ThrowingExtractor)2 CartoonCharacter (org.assertj.core.test.CartoonCharacter)2 ExpectedException (org.assertj.core.test.ExpectedException)2 Test (org.junit.Test)2 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1