org.llorllale.cactoos.matchers.HasValues Java Examples

The following examples show how to use org.llorllale.cactoos.matchers.HasValues. 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 File: ThreadsTest.java    From cactoos with MIT License 6 votes vote down vote up
/**
 * Execute the tasks concurrently using {@link Threads} when
 *  {@link ExecutorService} was initiated by {@link Threads} itself.
 */
@Test
public void containsValuesWithInlineExecutorService() {
    this.repeat(
        arg -> new Assertion<>(
            // @checkstyle LineLength (1 line)
            "contains results from the callables when using the inline executor service",
            new Threads<String>(
                3,
                () -> {
                    this.sleep();
                    return "txt 1";
                },
                () -> {
                    this.sleep();
                    return "txt 2";
                },
                () -> {
                    this.sleep();
                    return "txt 3";
                }
            ),
            new HasValues<>("txt 1", "txt 2", "txt 3")
        ).affirm()
    );
}
 
Example #2
Source File: HeadOfTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void iteratesForEachRemaining() throws Exception {
    final List<String> lst = new ArrayList<>(2);
    new HeadOf<>(
        2,
        new IteratorOf<>(
            "one", "two", "three", "four"
        )
    ).forEachRemaining(
        lst::add
    );
    new Assertion<>(
        "Should iterate over 2 head elements",
        lst,
        new HasValues<>(
            "one",
            "two"
        )
    ).affirm();
}
 
Example #3
Source File: HeadOfTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void headIterator() throws Exception {
    new Assertion<>(
        "Must skip elements in iterator",
        new IterableOf<>(
            new HeadOf<>(
                2,
                new IteratorOf<>(
                    "one", "two", "three", "four"
                )
            )
        ),
        new HasValues<>(
            "one",
            "two"
        )
    ).affirm();
}
 
Example #4
Source File: IteratorOfBytesTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void canBeConstructedFromText() throws Exception {
    final Iterator<Byte> itr = new IteratorOfBytes(
        new TextOf("ABC")
    );
    new Assertion<>(
        "Must have 3 elements",
        new ListOf<>(
            itr.next(),
            itr.next(),
            itr.next(),
            itr.hasNext()
        ),
        new HasValues<Object>(
            (byte) 'A', (byte) 'B', (byte) 'C', false
        )
    ).affirm();
}
 
Example #5
Source File: IteratorOfBytesTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void canBeConstructedFromString() throws Exception {
    final Iterator<Byte> itr = new IteratorOfBytes(
        "F"
    );
    new Assertion<>(
        "Must have 1 element",
        new ListOf<>(
            itr.next(),
            itr.hasNext()
        ),
        new HasValues<Object>(
            (byte) 'F', false
        )
    ).affirm();
}
 
Example #6
Source File: SkippedTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void skipIterator() {
    new Assertion<>(
        "Must skip elements in iterator",
        new IterableOf<>(
            new Skipped<>(
                2,
                new IteratorOf<>(
                    "one", "two", "three", "four"
                )
            )
        ),
        new HasValues<>(
            "three",
            "four"
        )
    ).affirm();
}
 
Example #7
Source File: SortedTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void sortsIterable() throws Exception {
    new Assertion<>(
        "Must sort elements in iterator",
        new IterableOf<>(
            new Sorted<>(
                new IteratorOf<>(
                    "one", "two", "three", "four"
                )
            )
        ),
        new HasValues<>(
            "four", "one", "three", "two"
        )
    ).affirm();
}
 
Example #8
Source File: ShuffledTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void shuffleIterable() throws Exception {
    new Assertion<>(
        "Must shuffle elements in iterator",
        new IterableOf<>(
            new Shuffled<>(
                new IteratorOf<>(
                    "a", "b"
                )
            )
        ),
        new HasValues<>(
            "a", "b"
        )
    ).affirm();
}
 
Example #9
Source File: HttpServletResponseFakeTest.java    From takes with MIT License 5 votes vote down vote up
@Test
public void sendError() throws IOException {
    final HttpServletResponse sresp = new HttpServletResponseFake(
        new RsEmpty()
    );
    // @checkstyle MagicNumber (1 line)
    sresp.sendError(101, "Switching Protocol");
    new Assertion<>(
        "Can't send a error in servlet response",
        sresp.getHeaders(HttpServletResponseFakeTest.VERSION),
        new HasValues<>(
            HttpServletResponseFakeTest.INFO
        )
    ).affirm();
}
 
Example #10
Source File: ThreadsTest.java    From cactoos with MIT License 5 votes vote down vote up
/**
 * Execute the tasks concurrently using {@link Threads} when
 *  {@link ExecutorService} was initiated by someone else.
 */
@Test
public void containsResults() {
    this.repeat(
        arg -> {
            final ExecutorService extor = Executors.newFixedThreadPool(3);
            try {
                new Assertion<>(
                    "contains results from callables",
                    new Threads<String>(
                        extor,
                        () -> {
                            this.sleep();
                            return "txt 1";
                        },
                        () -> {
                            this.sleep();
                            return "txt 2";
                        },
                        () -> {
                            this.sleep();
                            return "txt 3";
                        }
                    ),
                    new HasValues<>("txt 1", "txt 2", "txt 3")
                ).affirm();
            } finally {
                extor.shutdown();
                if (!extor.awaitTermination(1L, TimeUnit.SECONDS)) {
                    extor.shutdownNow();
                }
            }
        }
    );
}
 
Example #11
Source File: HttpServletResponseFakeTest.java    From takes with MIT License 5 votes vote down vote up
@Test
public void status() {
    final HttpServletResponse sresp = new HttpServletResponseFake(
        new RsEmpty()
    );
    // @checkstyle MagicNumber (1 line)
    sresp.setStatus(502);
    new Assertion<>(
        "Can't set a status in servlet response",
        sresp.getHeaders(HttpServletResponseFakeTest.VERSION),
        new HasValues<>(
            HttpServletResponseFakeTest.ERROR
        )
    ).affirm();
}
 
Example #12
Source File: XmlGraphTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
void buildsConnections() {
    final Map<String, Node> byname = new MapOf<>(
        Node::name,
        node -> node,
        new XmlGraph(
            new Skeleton(new FakeBase(XmlGraphTest.CLASS_NAME))
        ).nodes()
    );
    final Node one = byname.get(XmlGraphTest.METHOD_ONE);
    final Node two = byname.get(XmlGraphTest.METHOD_TWO);
    final Node three = byname.get(XmlGraphTest.METHOD_THREE);
    final Node four = byname.get(XmlGraphTest.METHOD_FOUR);
    final Node five = byname.get(XmlGraphTest.METHOD_FIVE);
    new Assertion<>(
        "Must build nodes connections when called",
        one.connections(),
        new HasValues<>(two)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when called or calling",
        two.connections(),
        new HasValues<>(one, four)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when neither called nor calling",
        three.connections(),
        new IsEmptyCollection<>()
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when calling",
        four.connections(),
        new HasValues<>(two)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when throwing",
        five.connections(),
        new IsEmptyCollection<>()
    ).affirm();
}
 
Example #13
Source File: ReportDataTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void reportsParams() throws Exception {
    final String name = "name";
    final Map<String, Object> sample = ReportDataTest.args();
    final ReportData data = new ReportData(name, sample);
    new Assertion<>(
        "Must returns args",
        data.params().entrySet(),
        new HasValues<>(sample.entrySet())
    ).affirm();
}
 
Example #14
Source File: IteratorOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertStringsToIterator() {
    new Assertion<>(
        "Must create an iterator of strings",
        new IterableOf<>(
            new IteratorOf<>(
                "a", "b", "c"
            )
        ),
        new HasValues<>(
            "a", "b", "c"
        )
    ).affirm();
}
 
Example #15
Source File: IteratorOfCharsTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void canBeConstructedFromText() {
    new Assertion<>(
        "Iterator must contain all characters of the string",
        new IterableOf<>(
            new IteratorOfChars(
                new TextOf("abc")
            )
        ),
        new HasValues<>('a', 'b', 'c')
    ).affirm();
}
 
Example #16
Source File: IterableOfBytesTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsBytesToIterable() {
    final byte[] bytes = "txt".getBytes();
    new Assertion<>(
        "Must create Iterable from bytes",
        new IterableOfBytes(bytes),
        new HasValues<>(bytes[0], bytes[1], bytes[2])
    ).affirm();
}
 
Example #17
Source File: IterableOfBytesTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsTextToIterableOfBytes() {
    new Assertion<>(
        "Must create Iterable from Text",
        new IterableOfBytes(
            new TextOf("ABC")
        ),
        new HasValues<>(
            (byte) 'A', (byte) 'B', (byte) 'C'
        )
    ).affirm();
}
 
Example #18
Source File: IterableOfCharsTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsCharactersToIterable() {
    new Assertion<>(
        "Must create Iterable from Text",
        new IterableOfChars(new TextOf("txt")),
        new HasValues<>('t', 'x', 't')
    ).affirm();
}
 
Example #19
Source File: ShuffledTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void shufflesIterable() {
    new Assertion<>(
        "Must shuffle elements in iterable",
        new Shuffled<>(new IterableOf<>(1, 2, 0, -1)),
        new HasValues<>(1, 2, 0, -1)
    ).affirm();
}
 
Example #20
Source File: ShuffledTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void shuffleCollection() {
    new Assertion<>(
        "Must shuffle elements in collection",
        new Shuffled<>(new ListOf<>(1, 2, 0, -1)),
        new HasValues<>(1, 2, 0, -1)
    ).affirm();
}
 
Example #21
Source File: ShuffledTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void shuffleArray() throws Exception {
    new Assertion<>(
        "Must shuffle an iterable",
        new Shuffled<>(
            new IterableOf<>(
                6, 2, 5
            )
        ),
        new HasValues<>(2, 5, 6)
    ).affirm();
}
 
Example #22
Source File: ImmutableTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void iterator() {
    new Assertion<>(
        "iterator() is equal to original",
        () -> new Immutable<>(
            new ListOf<>(1, 2)
        ).iterator(),
        new HasValues<>(1, 2)
    ).affirm();
}
 
Example #23
Source File: ImmutableTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void testListIterator() {
    new Assertion<>(
        "listIterator(int) is equal to original",
        () -> new Immutable<>(
            new ListOf<>("a", "b", "c", "b")
        ).listIterator(2),
        new HasValues<>("c", "b")
    ).affirm();
}
 
Example #24
Source File: ImmutableTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void listIterator() {
    new Assertion<>(
        "listIterator() is equal to original",
        () -> new Immutable<>(
            new ListOf<>("a", "b", "c", "b")
        ).listIterator(),
        new HasValues<>("a", "b", "c", "b")
    ).affirm();
}
 
Example #25
Source File: ImmutableTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void iterator() {
    new Assertion<>(
        "iterator() is equal to original",
        () -> new Immutable<>(
            new ListOf<>(1, 2)
        ).iterator(),
        new HasValues<>(1, 2)
    ).affirm();
}
 
Example #26
Source File: ShuffledTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void shufflesList() throws Exception {
    MatcherAssert.assertThat(
        "Can't shuffle elements in list",
        new Shuffled<>(
            new ListOf<>(1, 0, -1, -1, 2)
        ),
        new HasValues<>(-1)
    );
}
 
Example #27
Source File: TimedTest.java    From cactoos with MIT License 5 votes vote down vote up
/**
 * Execute the tasks concurrently using {@link Timed} when
 *  {@link ExecutorService} was initiated by {@link Timed} itself.
 */
@Test
public void containsValuesWithInlineExecutorService() {
    this.repeat(
        arg -> new Assertion<>(
            "Contains results from the callables when using the inline executor service",
            new Timed<String>(
                TimedTest.THREADS,
                1L,
                TimeUnit.SECONDS,
                () -> {
                    this.sleep();
                    return TimedTest.FIRST_TEXT;
                },
                () -> {
                    this.sleep();
                    return TimedTest.SECOND_TEXT;
                },
                () -> {
                    this.sleep();
                    return TimedTest.THIRD_TEXT;
                }
            ),
            new HasValues<>(TimedTest.FIRST_TEXT, TimedTest.SECOND_TEXT, TimedTest.THIRD_TEXT)
        ).affirm()
    );
}
 
Example #28
Source File: TimedTest.java    From cactoos with MIT License 4 votes vote down vote up
/**
 * Execute the tasks concurrently using {@link Timed} when
 *  {@link ExecutorService} was initiated by someone else.
 */
@Test
public void containsResults() {
    this.repeat(
        arg -> {
            final ExecutorService extor = Executors.newFixedThreadPool(TimedTest.THREADS);
            try {
                new Assertion<>(
                    "Contains results from callables",
                    new Timed<String>(
                        extor,
                        1L,
                        TimeUnit.SECONDS,
                        () -> {
                            this.sleep();
                            return TimedTest.FIRST_TEXT;
                        },
                        () -> {
                            this.sleep();
                            return TimedTest.SECOND_TEXT;
                        },
                        () -> {
                            this.sleep();
                            return TimedTest.THIRD_TEXT;
                        }
                    ),
                    new HasValues<>(
                        TimedTest.FIRST_TEXT,
                        TimedTest.SECOND_TEXT,
                        TimedTest.THIRD_TEXT
                    )
                ).affirm();
            } finally {
                extor.shutdown();
                if (!extor.awaitTermination(1L, TimeUnit.SECONDS)) {
                    extor.shutdownNow();
                }
            }
        }
    );
}