JavaHamcrest

JavaDoc
Tutorial

        assertThat(2, is(2));
        assertThat(2, not(1));
        assertThat(2, anything());
        assertThat(2, anyOf(is(2), is(3)));
        assertThat(2, allOf(is(2), not(3)));
        assertThat(2, equalTo(2));
        assertThat(23, hasToString("23"));
        assertThat(23, instanceOf(Integer.class));
 
        List<String> st = new ArrayList<>();
        st.add("st");
        st.add("st2");
        assertThat(st, hasItem("st"));
        assertThat(st, hasItems("st2", "st"));
        assertThat(st, contains("st", "st2"));
 
        Map<String, List<String>> map = new HashMap<>();
        map.put("key", st);
        map.put("key2", Arrays.asList("st1"));
 
        assertThat(map, hasKey("key"));
        assertThat(map, hasValue(allOf(hasItem("st2"), hasItem("st"))));
        assertThat(map, hasValue(hasItem("st1")));
        assertThat(map, hasEntry(is("key2"), hasItem("st1")));
Пока не указано иное, содержимое этой страницы распространяется по лицензии Creative Commons Attribution-ShareAlike 3.0 License