org.hamcrest.collection.IsEmptyCollection#org.cactoos.map.MapOf源码实例Demo

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

源代码1 项目: cactoos   文件: PropertiesOfTest.java
@Test
public void convertsMapToProperties() {
    new Assertion<>(
        "Must convert map to properties",
        new PropertiesOf(
            new Sticky<>(
                new MapOf<Integer, String>(
                    new MapEntry<>(0, "hello, world"),
                    new MapEntry<>(1, "how are you?")
                )
            )
        ),
        new ScalarHasValue<>(
            new MatcherOf<Properties>(
                props -> {
                    return props.getProperty("0").endsWith(", world");
                }
            )
        )
    ).affirm();
}
 
源代码2 项目: cactoos   文件: PropertiesOfTest.java
@Test
public void sensesChangesInMap() throws Exception {
    final AtomicInteger size = new AtomicInteger(2);
    final PropertiesOf props = new PropertiesOf(
        new MapOf<>(
            () -> new Repeated<>(
                size.incrementAndGet(), () -> new MapEntry<>(
                    new SecureRandom().nextInt(),
                    1
                )
            )
        )
    );
    new Assertion<>(
        "Must sense the changes in the underlying map",
        props.value().size(),
        new IsNot<>(new IsEqual<>(props.value().size()))
    ).affirm();
}
 
源代码3 项目: jpeek   文件: App.java
/**
 * Ctor.
 * @param source Source directory
 * @param target Target dir
 */
public App(final Path source, final Path target) {
    this(
        source, target,
        new MapOf<String, Object>(
            new MapEntry<>("LCOM", true),
            new MapEntry<>("LCOM2", true),
            new MapEntry<>("LCOM3", true),
            new MapEntry<>("LCOM4", true),
            new MapEntry<>("LCOM5", true),
            new MapEntry<>("SCOM", true),
            new MapEntry<>("NHD", true),
            new MapEntry<>("MMAC", true),
            new MapEntry<>("OCC", true),
            new MapEntry<>("PCC", true),
            new MapEntry<>("TCC", true),
            new MapEntry<>("LCC", true),
            new MapEntry<>("CCM", true),
            new MapEntry<>("MWE", true)
        )
    );
}
 
源代码4 项目: verano-http   文件: HashDict.java
/**
 * Ctor.
 * @param kvps Key-value pairs
 */
public HashDict(final Iterable<Kvp> kvps) {
    this(
        kvps,
        new MapOf<>(
            new Mapped<>(
                input -> new MapEntry<>(input.key(), input.value()),
                kvps
            )
        )
    );
}
 
源代码5 项目: cactoos   文件: PropertiesOf.java
/**
 * Ctor.
 * @param entries The map with properties
 * @since 0.23
 */
public PropertiesOf(final Iterable<Map.Entry<?, ?>> entries) {
    this(
        new MapOf<>(
            new Mapped<Map.Entry<?, ?>, Map.Entry<String, String>>(
                input -> new MapEntry<>(
                    input.getKey().toString(), input.getValue().toString()
                ),
                entries
            )
        )
    );
}
 
源代码6 项目: cactoos   文件: ScalarWithFallback.java
/**
 * Finds the best fallback for the given exception type and apply it to
 * the exception or throw the original error if no fallback found.
 * @param exp The original exception
 * @return Result of the most suitable fallback
 * @throws Exception The original exception if no fallback found
 */
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
private T fallback(final Throwable exp) throws Exception {
    final Sorted<Map.Entry<FallbackFrom<T>, Integer>> candidates =
        new Sorted<>(
            Comparator.comparing(Map.Entry::getValue),
            new Filtered<>(
                entry -> new Not(
                    new Equals<>(
                        entry::getValue,
                        () -> Integer.MIN_VALUE
                    )
                ).value(),
                new MapOf<>(
                    fbk -> fbk,
                    fbk -> fbk.support(exp.getClass()),
                    this.fallbacks
                ).entrySet().iterator()
            )
        );
    if (candidates.hasNext()) {
        return candidates.next().getKey().apply(exp);
    } else {
        throw new Exception(
            "No fallback found - throw the original exception",
            exp
        );
    }
}
 
源代码7 项目: 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();
}
 
源代码8 项目: cactoos-jdbc   文件: PhonebookTest.java
@Test
public void addContact() throws Exception {
    try (
        Servers servers = new Servers(
            new ServerH2(
                new ScriptSql(
                    new ResourceOf(
                        new Joined(
                            "/",
                            "com/github/fabriciofx/cactoos/jdbc/phonebook",
                            "phonebook-h2.sql"
                        )
                    )
                )
            ),
            new ServerPgsql(
                new ScriptSql(
                    new ResourceOf(
                        new Joined(
                            "/",
                            "com/github/fabriciofx/cactoos/jdbc/phonebook",
                            "phonebook-pgsql.sql"
                        )
                    )
                )
            )
        )
    ) {
        for (final Session session : servers.sessions()) {
            final Phonebook phonebook = new PhonebookSql(session);
            final Contact contact = phonebook.contact(
                new MapOf<String, String>(
                    new MapEntry<>("name", "Donald Knuth")
                )
            );
            contact.phones().add(
                new MapOf<String, String>(
                    new MapEntry<>("number", "99991234"),
                    new MapEntry<>("carrier", "TIM")
                )
            );
            contact.phones().add(
                new MapOf<String, String>(
                    new MapEntry<>("number", "98812564"),
                    new MapEntry<>("carrier", "Oi")
                )
            );
            MatcherAssert.assertThat(
                XhtmlMatchers.xhtml(
                    contact.about()
                ),
                XhtmlMatchers.hasXPaths(
                    "/contact/name[text()='Donald Knuth']",
                    "/contact/phones/phone/number[text()='99991234']",
                    "/contact/phones/phone/carrier[text()='TIM']",
                    "/contact/phones/phone/number[text()='98812564']",
                    "/contact/phones/phone/carrier[text()='Oi']"
                )
            );
        }
    }
}
 
源代码9 项目: cactoos-jdbc   文件: PhonebookTest.java
@Test
public void renameContact() throws Exception {
    try (
        Servers servers = new Servers(
            new ServerH2(
                new ScriptSql(
                    new ResourceOf(
                        new Joined(
                            "/",
                            "com/github/fabriciofx/cactoos/jdbc/phonebook",
                            "phonebook-h2.sql"
                        )
                    )
                )
            ),
            new ServerPgsql(
                new ScriptSql(
                    new ResourceOf(
                        new Joined(
                            "/",
                            "com/github/fabriciofx/cactoos/jdbc/phonebook",
                            "phonebook-pgsql.sql"
                        )
                    )
                )
            )
        )
    ) {
        for (final Session session : servers.sessions()) {
            final Phonebook phonebook = new PhonebookSql(session);
            final Contact contact = phonebook.filter("maria").iterator()
                .next();
            contact.update(
                new MapOf<String, String>(
                    new MapEntry<>("name", "Maria Lima")
                )
            );
            MatcherAssert.assertThat(
                XhtmlMatchers.xhtml(
                    new PhonebookSql(session)
                        .filter("maria")
                        .iterator()
                        .next()
                        .about()
                ),
                XhtmlMatchers.hasXPaths(
                    "/contact/name[text()='Maria Lima']"
                )
            );
        }
    }
}
 
源代码10 项目: cactoos-jdbc   文件: StatementTransactionTest.java
@Test
public void commit() throws Exception {
    final Transacted transacted = new Transacted(
        new SessionNoAuth(
            new SourceH2("safedb")
        )
    );
    new ScriptSql(
        new ResourceOf(
            "com/github/fabriciofx/cactoos/jdbc/phonebook/phonebook-h2.sql"
        )
    ).run(transacted);
    MatcherAssert.assertThat(
        "Can't perform a transaction commit",
        XhtmlMatchers.xhtml(
            new ResultAsValue<>(
                new StatementTransaction<>(
                    transacted,
                    () -> {
                        final Phonebook phonebook = new PhonebookSql(
                            transacted
                        );
                        final Contact contact = phonebook.contact(
                            new MapOf<String, String>(
                                new MapEntry<>("name", "Albert Einstein")
                            )
                        );
                        contact.phones().add(
                            new MapOf<String, String>(
                                new MapEntry<>("number", "99991234"),
                                new MapEntry<>("carrier", "TIM")
                            )
                        );
                        contact.phones().add(
                            new MapOf<String, String>(
                                new MapEntry<>("number", "98812564"),
                                new MapEntry<>("carrier", "Oi")
                            )
                        );
                        return contact.about();
                    }
                )
            ).value()
        ),
        XhtmlMatchers.hasXPaths(
            "/contact/name[text()='Albert Einstein']",
            "/contact/phones/phone/number[text()='99991234']",
            "/contact/phones/phone/carrier[text()='TIM']",
            "/contact/phones/phone/number[text()='98812564']",
            "/contact/phones/phone/carrier[text()='Oi']"
        )
    );
}
 
源代码11 项目: cactoos-jdbc   文件: StatementTransactionTest.java
@Test
public void rollback() throws Exception {
    final Transacted transacted = new Transacted(
        new SessionNoAuth(
            new SourceH2("unsafedb")
        )
    );
    new ScriptSql(
        new ResourceOf(
            "com/github/fabriciofx/cactoos/jdbc/phonebook/phonebook-h2.sql"
        )
    ).run(transacted);
    final Phonebook phonebook = new PhonebookSql(transacted);
    final String name = "Frank Miller";
    try {
        new StatementTransaction<>(
            transacted,
            () -> {
                final Contact contact = phonebook.contact(
                    new MapOf<String, String>(
                        new MapEntry<>("name", name)
                    )
                );
                contact.phones().add(
                    new MapOf<String, String>(
                        new MapEntry<>("number", "99991234"),
                        new MapEntry<>("carrier", "TIM")
                    )
                );
                throw new IllegalStateException("Rollback");
            }
        ).result();
    } catch (final IllegalStateException ex) {
    }
    MatcherAssert.assertThat(
        "Can't perform a transaction rollback",
        StreamSupport.stream(
            phonebook.filter(name).spliterator(),
            false
        ).count(),
        Matchers.equalTo(0L)
    );
}
 
源代码12 项目: jpeek   文件: ReportDataTest.java
private static Map<String, Object> args() {
    return new MapOf<String, Object>(
        new MapEntry<>("a", 1), new MapEntry<>("b", 2)
    );
}
 
源代码13 项目: jpeek   文件: ReportData.java
/**
 * Ctor.
 * @param name Name of the metric
 * @param args Params for XSL
 * @param mean Mean
 * @param sigma Sigma
 * @checkstyle ParameterNumberCheck (10 lines)
 */
ReportData(final String name, final Map<String, Object> args, final double mean,
    final double sigma) {
    this.metr = name;
    this.args = new MapOf<String, Object>(new HashMap<>(args));
    this.man = mean;
    this.sig = sigma;
}