org.hamcrest.collection.IsEmptyCollection#org.llorllale.cactoos.matchers.HasValues源码实例Demo

下面列出了org.hamcrest.collection.IsEmptyCollection#org.llorllale.cactoos.matchers.HasValues 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cactoos   文件: ThreadsTest.java
/**
 * 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()
    );
}
 
源代码2 项目: cactoos   文件: ShuffledTest.java
@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();
}
 
源代码3 项目: cactoos   文件: SortedTest.java
@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();
}
 
源代码4 项目: cactoos   文件: SkippedTest.java
@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();
}
 
源代码5 项目: cactoos   文件: IteratorOfBytesTest.java
@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();
}
 
源代码6 项目: cactoos   文件: IteratorOfBytesTest.java
@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();
}
 
源代码7 项目: cactoos   文件: HeadOfTest.java
@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();
}
 
源代码8 项目: cactoos   文件: HeadOfTest.java
@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();
}
 
源代码9 项目: cactoos   文件: ThreadsTest.java
/**
 * 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();
                }
            }
        }
    );
}
 
源代码10 项目: cactoos   文件: TimedTest.java
/**
 * 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()
    );
}
 
源代码11 项目: cactoos   文件: ShuffledTest.java
@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)
    );
}
 
源代码12 项目: cactoos   文件: ImmutableTest.java
@Test
public void iterator() {
    new Assertion<>(
        "iterator() is equal to original",
        () -> new Immutable<>(
            new ListOf<>(1, 2)
        ).iterator(),
        new HasValues<>(1, 2)
    ).affirm();
}
 
源代码13 项目: cactoos   文件: ImmutableTest.java
@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();
}
 
源代码14 项目: cactoos   文件: ImmutableTest.java
@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();
}
 
源代码15 项目: cactoos   文件: ImmutableTest.java
@Test
public void iterator() {
    new Assertion<>(
        "iterator() is equal to original",
        () -> new Immutable<>(
            new ListOf<>(1, 2)
        ).iterator(),
        new HasValues<>(1, 2)
    ).affirm();
}
 
源代码16 项目: cactoos   文件: ShuffledTest.java
@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();
}
 
源代码17 项目: cactoos   文件: ShuffledTest.java
@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();
}
 
源代码18 项目: cactoos   文件: ShuffledTest.java
@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();
}
 
源代码19 项目: cactoos   文件: IterableOfCharsTest.java
@Test
public void convertsCharactersToIterable() {
    new Assertion<>(
        "Must create Iterable from Text",
        new IterableOfChars(new TextOf("txt")),
        new HasValues<>('t', 'x', 't')
    ).affirm();
}
 
源代码20 项目: cactoos   文件: IterableOfBytesTest.java
@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();
}
 
源代码21 项目: cactoos   文件: IterableOfBytesTest.java
@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();
}
 
源代码22 项目: cactoos   文件: IteratorOfCharsTest.java
@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();
}
 
源代码23 项目: cactoos   文件: IteratorOfTest.java
@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();
}
 
源代码24 项目: jpeek   文件: ReportDataTest.java
@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();
}
 
源代码25 项目: jpeek   文件: XmlGraphTest.java
@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();
}
 
源代码26 项目: takes   文件: HttpServletResponseFakeTest.java
@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();
}
 
源代码27 项目: takes   文件: HttpServletResponseFakeTest.java
@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();
}
 
源代码28 项目: cactoos   文件: TimedTest.java
/**
 * 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();
                }
            }
        }
    );
}