/** * Creates a matcher that matches when the examined object has values for all of * its JavaBean properties that are equal to the corresponding values of the * specified bean. * <p/> * For example: * <pre>assertThat(myBean, samePropertyValuesAs(myExpectedBean))</pre> * * @param expectedBean * the bean against which examined beans are compared */ public static <T> org.hamcrest.Matcher<T> samePropertyValuesAs(T expectedBean) { return org.hamcrest.beans.SamePropertyValuesAs.<T>samePropertyValuesAs(expectedBean); }
/** * Creates a matcher that matches when the examined object has values for all of * its JavaBean properties that are equal to the corresponding values of the * specified bean. If any properties are marked as ignored, they will be dropped from * both the expected and actual bean. Note that the ignored properties use JavaBean * display names, for example <pre>age</pre> rather than method names such as <pre>getAge</pre>. * For example: * <pre>assertThat(myBean, samePropertyValuesAs(myExpectedBean))</pre> * <pre>assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")</pre> * * @param expectedBean * the bean against which examined beans are compared * @param ignoredProperties * do not check any of these named properties. */ public static <B> Matcher<B> samePropertyValuesAs(B expectedBean, String... ignoredProperties) { return org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs(expectedBean, ignoredProperties); }
@Override protected Matcher<?> createMatcher() { return samePropertyValuesAs(expectedBean); }
public void testDescribesItself() { assertDescription( "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: <Value expected>]", samePropertyValuesAs(expectedBean)); assertDescription( "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: <Value expected>] ignoring [\"ignored1\", \"ignored2\"]", samePropertyValuesAs(expectedBean, "ignored1", "ignored2")); }
public void test_reports_match_when_all_properties_match() { assertMatches("matched properties", samePropertyValuesAs(expectedBean), actualBean); }
public void test_reports_mismatch_when_actual_type_is_not_assignable_to_expected_type() { assertMismatchDescription("is incompatible type: ExampleBean", samePropertyValuesAs((Object)aValue), actualBean); }
public void test_accepts_missing_properties_to_ignore() { assertMatches("ignored property", samePropertyValuesAs(expectedBean, "notAProperty"), actualBean); }
public void test_matches_beans_with_inheritance_but_no_extra_properties() { assertMatches("sub type with same properties", samePropertyValuesAs(expectedBean), new SubBeanWithNoExtraProperties("same", 1, aValue)); }
public void test_rejects_subtype_that_has_extra_properties() { assertMismatchDescription("has extra properties called [extraProperty]", samePropertyValuesAs(expectedBean), new SubBeanWithExtraProperty("same", 1, aValue)); }
public void test_ignores_extra_subtype_properties() { final SubBeanWithExtraProperty withExtraProperty = new SubBeanWithExtraProperty("same", 1, aValue); assertMatches("extra property", samePropertyValuesAs(expectedBean, "extraProperty"), withExtraProperty); }
public void test_ignores_different_properties() { final ExampleBean differentBean = new ExampleBean("different", 1, aValue); assertMatches("different property", samePropertyValuesAs(expectedBean, "stringProperty"), differentBean); }
public void test_reports_mismatch_on_first_property_difference() { assertMismatchDescription("stringProperty was \"different\"", samePropertyValuesAs(expectedBean), new ExampleBean("different", 1, aValue)); assertMismatchDescription("intProperty was <2>", samePropertyValuesAs(expectedBean), new ExampleBean("same", 2, aValue)); assertMismatchDescription("valueProperty was <Value other>", samePropertyValuesAs(expectedBean), new ExampleBean("same", 1, new Value("other"))); }
public void test_can_ignore_all_properties() { final ExampleBean differentBean = new ExampleBean("different", 2, new Value("not expected")); assertMatches( "different property", samePropertyValuesAs(expectedBean, "stringProperty", "intProperty", "valueProperty"), differentBean); }
/** * Creates a matcher that matches when the examined object has values for all of * its JavaBean properties that are equal to the corresponding values of the * specified bean. * For example: * <pre>assertThat(myBean, samePropertyValuesAs(myExpectedBean))</pre> * * @param expectedBean * the bean against which examined beans are compared */ public static <T> org.hamcrest.Matcher<T> samePropertyValuesAs(T expectedBean) { return org.hamcrest.beans.SamePropertyValuesAs.<T>samePropertyValuesAs(expectedBean); }
@Test void testGetDefaultBlacklistEntries() { BlackList blackList = new BlackList(); assertThat(defaultBlacklistEntries, samePropertyValuesAs(blackList.getBlacklistEntries())); }
@Test void testAddToDefaultBlacklistEntries() { List<BlacklistEntry> expectedEntries = new ArrayList<>(); expectedEntries.addAll(defaultBlacklistEntries); List<BlacklistEntry> newEntries = new ArrayList<>(Arrays.asList(new BlacklistEntry("new.entry", 404))); expectedEntries.addAll(newEntries); BlackList blackList = new BlackList(); blackList.addToDefaultBlacklistEntries(newEntries); assertThat(expectedEntries, samePropertyValuesAs(blackList.getBlacklistEntries())); }
@Test void testNewBlacklistEntries() { List<BlacklistEntry> newEntries = new ArrayList<>(Arrays.asList(new BlacklistEntry("new.entry", 404))); BlackList blackList = new BlackList(newEntries); assertThat(newEntries, samePropertyValuesAs(blackList.getBlacklistEntries())); }
@Test public void GET_whenTheUserHasPermissionToAccessPermissions_returnPermissions() throws Exception { RequestHelper.grantPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN, USER_A_ACTOR_ID, "read"); final PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN); assertThat(permissions.getCredentialName(), equalTo(credentialName)); assertThat(permissions.getPermissions(), contains( samePropertyValuesAs( new PermissionEntry(USER_A_ACTOR_ID, credentialName, asList(PermissionOperation.READ))) )); }
@Test public void GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions() throws Exception { RequestHelper.grantPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN, USER_A_ACTOR_ID, "read"); final PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialNameWithoutLeadingSlash, ALL_PERMISSIONS_TOKEN); assertThat(permissions.getCredentialName(), equalTo(credentialName)); assertThat(permissions.getPermissions(), contains( samePropertyValuesAs(new PermissionEntry(USER_A_ACTOR_ID, credentialName, asList(PermissionOperation.READ))) )); }
@Test public void POST_whenTheUserHasPermissionToWritePermissions_updatesPermissions() throws Exception { RequestHelper.grantPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN, USER_A_ACTOR_ID, "read", "delete"); RequestHelper.grantPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN, USER_A_ACTOR_ID, "write", "read"); final PermissionsView acl = RequestHelper .getPermissions(mockMvc, credentialName, ALL_PERMISSIONS_TOKEN); assertThat(acl.getPermissions(), hasSize(1)); assertThat(acl.getCredentialName(), equalTo(credentialName)); assertThat(acl.getPermissions(), contains( samePropertyValuesAs( new PermissionEntry(USER_A_ACTOR_ID, credentialName, asList( PermissionOperation.READ, PermissionOperation.WRITE, PermissionOperation.DELETE))) )); }