org.hamcrest.core.AllOf Java Examples

The following examples show how to use org.hamcrest.core.AllOf. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: cactoos   Author: yegor256   File: MapOfTest.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void createsMapFromMapAndMapEntries() {
    MatcherAssert.assertThat(
        "Can't create a map from map and map entries",
        new MapOf<Integer, Integer>(
            new MapOf<Integer, Integer>(
                new MapEntry<Integer, Integer>(0, 0)
            ),
            new MapEntry<Integer, Integer>(1, 1)
        ),
        new AllOf<>(
            new IterableOf<>(
                new IsMapContaining<>(new IsEqual<>(0), new IsEqual<>(0)),
                new IsMapContaining<>(new IsEqual<>(1), new IsEqual<>(1))
            )
        )
    );
}
 
Example #2
Source Project: cactoos   Author: yegor256   File: MapOfTest.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void createsMapFromMapFunctionsAndIterable() {
    MatcherAssert.assertThat(
        "Can't create a map from map, functions and iterable.",
        new MapOf<Integer, Integer>(
            new FuncOf<Integer, Integer>(0),
            new FuncOf<Integer, Integer>(0),
            new MapOf<Integer, Integer>(
                new MapEntry<Integer, Integer>(1, 1)
            ),
            new IterableOf<>(0)
        ),
        new AllOf<>(
            new IterableOf<>(
                new IsMapContaining<>(new IsEqual<>(0), new IsEqual<>(0)),
                new IsMapContaining<>(new IsEqual<>(1), new IsEqual<>(1))
            )
        )
    );
}
 
Example #3
Source Project: cactoos   Author: yegor256   File: NoNullsTest.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void entrySet() {
    MatcherAssert.assertThat(
        "Can't call #entrySet()",
        new NoNulls<Integer, Integer>(
            new HashMap<Integer, Integer>() {
                {
                    put(1, 1);
                    put(0, 0);
                }
            }
        ),
        new AllOf<>(
            new IterableOf<>(
                new IsMapContaining<>(new IsEqual<>(1), new IsEqual<>(1)),
                new IsMapContaining<>(new IsEqual<>(0), new IsEqual<>(0))
            )
        )
    );
}
 
Example #4
Source Project: cactoos   Author: yegor256   File: SolidTest.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void mapsIterableWithKeyFuncAndValueFunc() {
    final Solid<String, String> map = new Solid<>(
        key -> new Sub(new TextOf(key), 0, 1).asString(),
        value -> new Upper(new TextOf(value)).asString(),
        new IterableOf<>("aa", "bb")
    );
    MatcherAssert.assertThat(
        "Functions are not applied to key and value",
        map,
        new AllOf<>(
            new IterableOf<>(
                new IsMapContaining<>(
                    new IsEqual<>("a"),
                    new IsEqual<>("AA")
                ),
                new IsMapContaining<>(
                    new IsEqual<>("b"),
                    new IsEqual<>("BB")
                ),
                new MatcherOf<>(m -> m.size() == 2)
            )
        )
    );
}
 
Example #5
Source Project: cactoos   Author: yegor256   File: SetOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void behaveAsSetMergedCollectionsOfLiteralsWithDuplicates() {
    new Assertion<>(
        "Must keep unique string literals",
        new SetOf<String>(
            new Joined<String>(
                new IterableOf<>("cc", "ff"),
                new IterableOf<>("aa", "bb", "cc", "dd")
            )
        ),
        new AllOf<>(
            new IterableOf<Matcher<? super SetOf<String>>>(
                new HasSize(5),
                new IsCollectionContaining<>(new IsEqual<>("aa")),
                new IsCollectionContaining<>(new IsEqual<>("bb")),
                new IsCollectionContaining<>(new IsEqual<>("cc")),
                new IsCollectionContaining<>(new IsEqual<>("dd")),
                new IsCollectionContaining<>(new IsEqual<>("ff"))
            )
        )
    ).affirm();
}
 
Example #6
Source Project: cactoos   Author: yegor256   File: SetOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void behaveAsSetWithOriginalDuplicationsOfCharsInTheMiddle() {
    new Assertion<>(
        "Must keep unique characters",
        new SetOf<>('a', 'b', 'b', 'c', 'a', 'b', 'd'),
        new AllOf<>(
            new IterableOf<Matcher<? super SetOf<Character>>>(
                new HasSize(4),
                new IsCollectionContaining<>(new IsEqual<>('a')),
                new IsCollectionContaining<>(new IsEqual<>('b')),
                new IsCollectionContaining<>(new IsEqual<>('c')),
                new IsCollectionContaining<>(new IsEqual<>('d'))
            )
        )
    ).affirm();
}
 
Example #7
Source Project: cactoos   Author: yegor256   File: SetOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void behaveAsSetWithOriginalDuplicationsOfTextsInTheMiddle() {
    new Assertion<>(
        "Must keep unique TextOf objects",
        new SetOf<>(
            new TextOf("12345"),
            new TextOf("67890"),
            new TextOf("12345"),
            new TextOf("00000")
        ),
        new AllOf<>(
            new IterableOf<Matcher<? super SetOf<TextOf>>>(
                new HasSize(3),
                new IsCollectionContaining<>(
                    new IsEqual<>(new TextOf("12345"))
                ),
                new IsCollectionContaining<>(
                    new IsEqual<>(new TextOf("67890"))
                ),
                new IsCollectionContaining<>(
                    new IsEqual<>(new TextOf("00000"))
                )
            )
        )
    ).affirm();
}
 
Example #8
Source Project: cactoos   Author: yegor256   File: InputAsBytesTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsInputIntoBytes() throws Exception {
    new Assertion<>(
        "must read bytes from Input",
        new TextOf(
            new InputAsBytes(
                new InputOf(
                    new BytesOf(
                        new TextOf("Hello, друг!")
                    )
                )
            ),
            StandardCharsets.UTF_8
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith("Hello, "),
                new EndsWith("друг!")
            )
        )
    ).affirm();
}
 
Example #9
Source Project: cactoos   Author: yegor256   File: InputAsBytesTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsInputIntoBytesWithSmallBuffer() throws Exception {
    new Assertion<>(
        "must read bytes from Input with a small reading buffer",
        new TextOf(
            new InputAsBytes(
                new InputOf(
                    new BytesOf(
                        new TextOf("Hello, товарищ!")
                    )
                ),
                2
            ),
            StandardCharsets.UTF_8
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith("Hello,"),
                new EndsWith("товарищ!")
            )
        )
    ).affirm();
}
 
Example #10
Source Project: cactoos   Author: yegor256   File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsStringIntoBytes() throws Exception {
    new Assertion<>(
        "must read bytes from Input",
        new TextOf(
            new BytesOf(
                new InputOf("Hello, друг!")
            ),
            StandardCharsets.UTF_8
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith("Hello, "),
                new EndsWith("друг!")
            )
        )
    ).affirm();
}
 
Example #11
Source Project: cactoos   Author: yegor256   File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsStringBuilder() throws Exception {
    final String starts = "Name it, ";
    final String ends = "then it exists!";
    new Assertion<>(
        "must receive a string builder",
        new TextOf(
            new BytesOf(
                new InputOf(
                    new StringBuilder(starts)
                        .append(ends)
                )
            )
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith(starts),
                new EndsWith(ends)
            )
        )
    ).affirm();
}
 
Example #12
Source Project: cactoos   Author: yegor256   File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsStringBuffer() throws Exception {
    final String starts = "The future ";
    final String ends = "is now!";
    new Assertion<>(
        "must receive a string buffer",
        new TextOf(
            new BytesOf(
                new InputOf(
                    new StringBuffer(starts)
                        .append(ends)
                )
            )
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith(starts),
                new EndsWith(ends)
            )
        )
    ).affirm();
}
 
Example #13
Source Project: cactoos   Author: yegor256   File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsArrayOfChars() throws Exception {
    new Assertion<>(
        "must read array of chars.",
        new TextOf(
            new BytesOf(
                new InputOf(
                    'H', 'o', 'l', 'd', ' ',
                    'i', 'n', 'f', 'i', 'n', 'i', 't', 'y'
                )
            )
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith("Hold "),
                new EndsWith("infinity")
            )
        )
    ).affirm();
}
 
Example #14
Source Project: cactoos   Author: yegor256   File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsEncodedArrayOfChars() throws Exception {
    new Assertion<>(
        "must read array of encoded chars.",
        new TextOf(
            new BytesOf(
                new InputOf(
                    new char[]{
                        'O', ' ', 'q', 'u', 'e', ' ', 's', 'e', 'r', 'a',
                        ' ', 'q', 'u', 'e', ' ', 's', 'e', 'r', 'a',
                    },
                    StandardCharsets.UTF_8
                )
            ),
            StandardCharsets.UTF_8
        ),
        new AllOf<>(
            new IterableOf<>(
                new StartsWith("O que sera"),
                new EndsWith(" que sera")
            )
        )
    ).affirm();
}
 
Example #15
Source Project: zulip-android   Author: zulip   File: RecyclerViewTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void sendStreamMessage() {
    //Wait to make sure the messages are loaded
    sleep(2000);

    onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withMessageHolderAndClick(MessageType.STREAM_MESSAGE, R.id.contentView)));
    sleep(1000);

    //Fill message EditText
    ViewInteraction messageInteraction = onView(allOf(withId(R.id.message_et), isDisplayed()));
    messageInteraction.perform(replaceText(testMessageStream));

    //Click Send Button
    ViewInteraction imageView = onView(allOf(withId(R.id.send_btn), isDisplayed()));
    imageView.perform(click());

    sleep(2000);

    //Scroll And check the new sent message
    onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withMessageHolder(testMessageStream, R.id.contentView)));

    onView(AllOf.allOf(withId(R.id.contentView), withText(testMessageStream))).check(matches(isDisplayed()));

    checkIfMessagesMatchTheHeaderParent();
    checkOrderOfMessagesCurrentList();
}
 
Example #16
Source Project: zulip-android   Author: zulip   File: RecyclerViewTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void sendPrivateMessage() {
    //Wait to make sure the messages are loaded
    sleep(2000);

    onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withMessageHolderAndClick(MessageType.PRIVATE_MESSAGE, R.id.contentView)));
    sleep(1000);

    //Fill message EditText
    ViewInteraction messageInteraction = onView(allOf(withId(R.id.message_et), isDisplayed()));
    messageInteraction.perform(replaceText(testMessagePrivate));

    //Click Send Button
    ViewInteraction imageView = onView(allOf(withId(R.id.send_btn), isDisplayed()));
    imageView.perform(click());

    sleep(2000);

    //Scroll And check the new sent message
    onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withMessageHolder(testMessagePrivate, R.id.contentView)));

    onView(AllOf.allOf(withId(R.id.contentView), withText(testMessagePrivate))).check(matches(isDisplayed()));

    checkIfMessagesMatchTheHeaderParent();
    checkOrderOfMessagesCurrentList();
}
 
Example #17
Source Project: ehcache3   Author: ehcache   File: MultiGettingStarted.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void multipleConfigurations() {
  //tag::multipleManagers[]
  XmlMultiConfiguration multipleConfiguration = XmlMultiConfiguration
    .from(getClass().getResource("/configs/docs/multi/multiple-managers.xml")) // <1>
    .build(); // <2>

  Configuration fooConfiguration = multipleConfiguration.configuration("foo-manager"); // <3>
  //end::multipleManagers[]

  Assert.assertThat(resourceMap(multipleConfiguration.identities().stream().collect(
    Collectors.toMap(Function.identity(), multipleConfiguration::configuration)
  )), AllOf.allOf(
    IsMapContaining.hasEntry(Is.is("foo-manager"), IsMapContaining.hasEntry(Is.is("foo"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP))),
    IsMapContaining.hasEntry(Is.is("bar-manager"), IsMapContaining.hasEntry(Is.is("bar"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP)))
  ));
}
 
Example #18
Source Project: ehcache3   Author: ehcache   File: MultiGettingStarted.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void multipleVariants() {
  //tag::multipleVariants[]
  XmlMultiConfiguration variantConfiguration = XmlMultiConfiguration
    .from(getClass().getResource("/configs/docs/multi/multiple-variants.xml"))
    .build();

  Configuration fooConfiguration = variantConfiguration.configuration("foo-manager", "offheap"); // <1>
  //end::multipleVariants[]

  Assert.assertThat(resourceMap(variantConfiguration.identities().stream().collect(
    Collectors.toMap(Function.identity(), i -> variantConfiguration.configuration(i, "offheap"))
  )), AllOf.allOf(
    IsMapContaining.hasEntry(Is.is("foo-manager"), IsMapContaining.hasEntry(Is.is("foo"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP))),
    IsMapContaining.hasEntry(Is.is("bar-manager"), IsMapContaining.hasEntry(Is.is("bar"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP)))
  ));

  Assert.assertThat(resourceMap(variantConfiguration.identities().stream().collect(
    Collectors.toMap(Function.identity(), i -> variantConfiguration.configuration(i, "heap"))
  )), AllOf.allOf(
    IsMapContaining.hasEntry(Is.is("foo-manager"), IsMapContaining.hasEntry(Is.is("foo"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP))),
    IsMapContaining.hasEntry(Is.is("bar-manager"), IsMapContaining.hasEntry(Is.is("bar"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP)))
  ));
}
 
Example #19
Source Project: ehcache3   Author: ehcache   File: MultiGettingStarted.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void multipleRetrieval() {
  XmlMultiConfiguration multipleConfiguration = XmlMultiConfiguration
    .from(getClass().getResource("/configs/docs/multi/multiple-managers.xml"))
    .build();
  XmlMultiConfiguration variantConfiguration = XmlMultiConfiguration
    .from(getClass().getResource("/configs/docs/multi/multiple-variants.xml"))
    .build();

  //tag::multipleRetrieval[]
  Map<String, Configuration> allConfigurations = multipleConfiguration.identities().stream() // <1>
    .collect(Collectors.toMap(i -> i, i -> multipleConfiguration.configuration(i))); // <2>
  Map<String, Configuration> offheapConfigurations = variantConfiguration.identities().stream()
    .collect(Collectors.toMap(i -> i, i -> variantConfiguration.configuration(i, "offheap"))); // <3>
  //end::multipleRetrieval[]

  Assert.assertThat(resourceMap(allConfigurations), AllOf.allOf(
    IsMapContaining.hasEntry(Is.is("foo-manager"), IsMapContaining.hasEntry(Is.is("foo"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP))),
    IsMapContaining.hasEntry(Is.is("bar-manager"), IsMapContaining.hasEntry(Is.is("bar"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP)))
  ));

  Assert.assertThat(resourceMap(offheapConfigurations), AllOf.allOf(
    IsMapContaining.hasEntry(Is.is("foo-manager"), IsMapContaining.hasEntry(Is.is("foo"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP, ResourceType.Core.OFFHEAP))),
    IsMapContaining.hasEntry(Is.is("bar-manager"), IsMapContaining.hasEntry(Is.is("bar"), IsIterableContainingInAnyOrder.containsInAnyOrder(ResourceType.Core.HEAP)))
  ));
}
 
Example #20
Source Project: lib-recur   Author: dmfs   File: ResultsMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(results(DateTime.parse("20180101"), 10),
            AllOf.<Matcher<RecurrenceRule>>allOf(
                    matches(new RecurrenceRule("FREQ=DAILY;COUNT=10")),
                    mismatches(new RecurrenceRule("FREQ=DAILY;COUNT=9"), "number of instances was <9>"),
                    mismatches(new RecurrenceRule("FREQ=DAILY;COUNT=12"), "number of instances was <12>"),
                    describesAs("number of instances is <10>")
            ));

    assertThat(results(DateTime.parse("20180101"), lessThan(20)),
            AllOf.<Matcher<RecurrenceRule>>allOf(
                    matches(new RecurrenceRule("FREQ=DAILY;COUNT=1")),
                    matches(new RecurrenceRule("FREQ=DAILY;COUNT=19")),
                    mismatches(new RecurrenceRule("FREQ=DAILY;COUNT=20"), "number of instances <20> was equal to <20>"),
                    mismatches(new RecurrenceRule("FREQ=DAILY;COUNT=21"), "number of instances <21> was greater than <20>"),
                    describesAs("number of instances is a value less than <20>")
            ));
}
 
Example #21
Source Project: lib-recur   Author: dmfs   File: YearMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(inYear(2018),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20181001T010001Z")),
                    mismatches(DateTime.parse("20210901T005959Z"), "year was <2021>"),
                    mismatches(DateTime.parse("20171101T010000Z"), "year was <2017>"),
                    describesAs("year (<2018>)")
            ));
    assertThat(inYear(2018, 2019, 2020),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20181001T010001Z")),
                    matches(DateTime.parse("20190801T010002Z")),
                    matches(DateTime.parse("20200601T010003Z")),
                    mismatches(DateTime.parse("20110501T005959Z"), "year was <2011>"),
                    mismatches(DateTime.parse("20170701T005958Z"), "year was <2017>"),
                    mismatches(DateTime.parse("20210901T005957Z"), "year was <2021>"),
                    mismatches(DateTime.parse("20301101T010000Z"), "year was <2030>"),
                    describesAs("year (<2018> or <2019> or <2020>)")
            ));

}
 
Example #22
Source Project: lib-recur   Author: dmfs   File: WeekDayMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(onWeekDay(Weekday.WE),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180808T010001Z")),
                    mismatches(DateTime.parse("20180809T005959Z"), "weekday was <TH>"),
                    mismatches(DateTime.parse("20180807T010000Z"), "weekday was <TU>"),
                    describesAs("weekday (<WE>)")
            ));
    assertThat(onWeekDay(Weekday.MO, Weekday.WE, Weekday.FR),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180808T010001Z")),
                    matches(DateTime.parse("20180806T010002Z")),
                    matches(DateTime.parse("20180810T010003Z")),
                    mismatches(DateTime.parse("20180805T005959Z"), "weekday was <SU>"),
                    mismatches(DateTime.parse("20180804T005958Z"), "weekday was <SA>"),
                    mismatches(DateTime.parse("20180814T005957Z"), "weekday was <TU>"),
                    mismatches(DateTime.parse("20180816T010000Z"), "weekday was <TH>"),
                    describesAs("weekday (<MO> or <WE> or <FR>)")
            ));

}
 
Example #23
Source Project: lib-recur   Author: dmfs   File: DayOfMonthMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(onDayOfMonth(10),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180710T010001Z")),
                    mismatches(DateTime.parse("20181001T005959Z"), "day of month was <1>"),
                    mismatches(DateTime.parse("20181011T010000Z"), "day of month was <11>"),
                    describesAs("day of month (<10>)")
            ));
    assertThat(onDayOfMonth(6, 8, 10),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180706T010001Z")),
                    matches(DateTime.parse("20180708T010002Z")),
                    matches(DateTime.parse("20180710T010003Z")),
                    mismatches(DateTime.parse("20180605T005959Z"), "day of month was <5>"),
                    mismatches(DateTime.parse("20180811T005958Z"), "day of month was <11>"),
                    mismatches(DateTime.parse("20181009T005957Z"), "day of month was <9>"),
                    mismatches(DateTime.parse("20180907T010000Z"), "day of month was <7>"),
                    describesAs("day of month (<6> or <8> or <10>)")
            ));
}
 
Example #24
Source Project: lib-recur   Author: dmfs   File: DayOfYearMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(onDayOfYear(10),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180110T010001Z")),
                    mismatches(DateTime.parse("20180111T005959Z"), "day of year was <11>"),
                    mismatches(DateTime.parse("20180109T010000Z"), "day of year was <9>"),
                    describesAs("day of year (<10>)")
            ));
    assertThat(onDayOfYear(1, 8, 365),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180101T010001Z")),
                    matches(DateTime.parse("20180108T010002Z")),
                    matches(DateTime.parse("20181231T010003Z")),
                    mismatches(DateTime.parse("20180102T005959Z"), "day of year was <2>"),
                    mismatches(DateTime.parse("20180107T005959Z"), "day of year was <7>"),
                    mismatches(DateTime.parse("20180109T005959Z"), "day of year was <9>"),
                    mismatches(DateTime.parse("20180228T005958Z"), "day of year was <59>"),
                    mismatches(DateTime.parse("20181230T005957Z"), "day of year was <364>"),
                    describesAs("day of year (<1> or <8> or <365>)")
            ));
}
 
Example #25
Source Project: lib-recur   Author: dmfs   File: MonthMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(inMonth(10),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20181001T010001Z")),
                    mismatches(DateTime.parse("20180901T005959Z"), "month was <9>"),
                    mismatches(DateTime.parse("20181101T010000Z"), "month was <11>"),
                    describesAs("month (<10>)")
            ));
    assertThat(inMonth(6, 8, 10),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20181001T010001Z")),
                    matches(DateTime.parse("20180801T010002Z")),
                    matches(DateTime.parse("20180601T010003Z")),
                    mismatches(DateTime.parse("20180501T005959Z"), "month was <5>"),
                    mismatches(DateTime.parse("20180701T005958Z"), "month was <7>"),
                    mismatches(DateTime.parse("20180901T005957Z"), "month was <9>"),
                    mismatches(DateTime.parse("20181101T010000Z"), "month was <11>"),
                    describesAs("month (<6> or <8> or <10>)")
            ));
}
 
Example #26
Source Project: lib-recur   Author: dmfs   File: BeforeMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(before(DateTime.parse("20180101T010000Z")),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180101T000059Z")),
                    mismatches(DateTime.parse("20180101T010001Z"), "not before 20180101T010000Z"),
                    mismatches(DateTime.parse("20180101T010000Z"), "not before 20180101T010000Z"),
                    describesAs("before 20180101T010000Z")
            ));

    assertThat(before("20180101T010000Z"),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180101T000059Z")),
                    mismatches(DateTime.parse("20180101T010001Z"), "not before 20180101T010000Z"),
                    mismatches(DateTime.parse("20180101T010000Z"), "not before 20180101T010000Z"),
                    describesAs("before 20180101T010000Z")
            ));
}
 
Example #27
Source Project: lib-recur   Author: dmfs   File: AfterMatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception
{
    assertThat(after(DateTime.parse("20180101T010000Z")),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180101T010001Z")),
                    mismatches(DateTime.parse("20180101T005959Z"), "not after 20180101T010000Z"),
                    mismatches(DateTime.parse("20180101T010000Z"), "not after 20180101T010000Z"),
                    describesAs("after 20180101T010000Z")
            ));

    assertThat(after("20180101T010000Z"),
            AllOf.<Matcher<DateTime>>allOf(
                    matches(DateTime.parse("20180101T010001Z")),
                    mismatches(DateTime.parse("20180101T005959Z"), "not after 20180101T010000Z"),
                    mismatches(DateTime.parse("20180101T010000Z"), "not after 20180101T010000Z"),
                    describesAs("after 20180101T010000Z")
            ));
}
 
Example #28
Source Project: cactoos   Author: yegor256   File: SolidTest.java    License: MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void mapsIterableWithMapEntryFunc() {
    MatcherAssert.assertThat(
        "Function are not applied to entry",
        new Solid<>(
            entry -> new MapEntry<>(
                new Sub(new TextOf(entry), 0, 1).asString(),
                new Upper(new TextOf(entry)).asString()
            ),
            new IterableOf<>("aa", "bb")
        ),
        new AllOf<>(
            new IterableOf<>(
                new IsMapContaining<>(
                    new IsEqual<>("a"),
                    new IsEqual<>("AA")
                ),
                new IsMapContaining<>(
                    new IsEqual<>("b"),
                    new IsEqual<>("BB")
                ),
                new MatcherOf<>(m -> m.size() == 2)
            )
        )
    );
}
 
Example #29
Source Project: cactoos   Author: yegor256   File: SetOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void behaveAsSetWithOriginalDuplicationsInTheTail() {
    new Assertion<>(
        "Must keep unique integer numbers",
        new SetOf<>(1, 2, 2),
        new AllOf<>(
            new IterableOf<Matcher<? super SetOf<Integer>>>(
                new HasSize(2),
                new IsCollectionContaining<>(new IsEqual<>(1)),
                new IsCollectionContaining<>(new IsEqual<>(2))
            )
        )
    ).affirm();
}
 
Example #30
Source Project: cactoos   Author: yegor256   File: SetOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void behaveAsSetWithOriginalDuplicationsInTheHead() {
    new Assertion<>(
        "Must keep unique integer numbers",
        new SetOf<>(1, 1, 2, 3),
        new AllOf<>(
            new IterableOf<Matcher<? super SetOf<Integer>>>(
                new HasSize(3),
                new IsCollectionContaining<>(new IsEqual<>(1)),
                new IsCollectionContaining<>(new IsEqual<>(2)),
                new IsCollectionContaining<>(new IsEqual<>(3))
            )
        )
    ).affirm();
}