/** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name whose value satisfies the specified matcher. * <p/> * For example: * <pre>assertThat(myBean, hasProperty("foo", equalTo("bar"))</pre> * * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean */ public static <T> org.hamcrest.Matcher<T> hasProperty(java.lang.String propertyName, org.hamcrest.Matcher<?> valueMatcher) { return org.hamcrest.beans.HasPropertyWithValue.<T>hasProperty(propertyName, valueMatcher); }
/** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name whose value satisfies the specified matcher. * For example: * <pre>assertThat(myBean, hasProperty("foo", equalTo("bar"))</pre> * * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean */ public static <T> org.hamcrest.Matcher<T> hasProperty(java.lang.String propertyName, org.hamcrest.Matcher<?> valueMatcher) { return org.hamcrest.beans.HasPropertyWithValue.hasProperty(propertyName, valueMatcher); }
public void testCanAccessAnAnonymousInnerClass() { class X implements IX { @Override public int getTest() { return 1; } } assertThat(new X(), HasPropertyWithValue.hasProperty("test", IsEqual.equalTo(1))); }
public void testMatchesBeanWithInfoWithMatchedNamedProperty() { assertMatches("with bean info", hasProperty("property", equalTo("with info")), beanWithInfo); assertMismatchDescription("property 'property' was \"with info\"", hasProperty("property", equalTo("without info")), beanWithInfo); }
public void testDescribeTo() { assertDescription("hasProperty(\"property\", <true>)", hasProperty("property", equalTo(true))); }
@Override protected Matcher<?> createMatcher() { return hasProperty("irrelevant", anything()); }
public void testMatchesBeanWithoutInfoWithMatchedNamedProperty() { final Matcher<BeanWithoutInfo> propertyMatcher = hasProperty("property", equalTo("is expected")); assertMatches("with property", propertyMatcher, shouldMatch); assertMismatchDescription("property 'property' was \"not expected\"", propertyMatcher, shouldNotMatch); }
public void testMatchesBeanWithoutInfoWithMatchedNamedBooleanProperty() { final Matcher<BeanWithoutInfo> booleanPropertyMatcher = hasProperty("booleanProperty", is(true)); assertMatches("with property", booleanPropertyMatcher, shouldMatch); assertMismatchDescription("property 'booleanProperty' was <false>", booleanPropertyMatcher, shouldNotMatch); }
public void testDoesNotMatchWriteOnlyProperty() { assertMismatchDescription("property \"writeOnlyProperty\" is not readable", hasProperty("writeOnlyProperty", anything()), shouldNotMatch); }
public void testMatchesPropertyAndValue() { assertMatches("property with value", hasProperty("property", anything()), beanWithInfo); }
public void testDoesNotMatchBeanWithoutInfoOrMatchedNamedProperty() { assertMismatchDescription("No property \"nonExistentProperty\"", hasProperty("nonExistentProperty", anything()), shouldNotMatch); }
public void testDescribesMissingPropertyMismatch() { assertMismatchDescription("No property \"honk\"", hasProperty("honk", anything()), shouldNotMatch); }
public void testDoesNotWriteMismatchIfPropertyMatches() { Description description = new StringDescription(); hasProperty( "property", anything()).describeMismatch(beanWithInfo, description); assertEquals("Expected mismatch description", "", description.toString()); }
public void testExceptionsInBeanMethodsShouldBeReportedCorrectly() { assertMismatchDescription( "Calling 'public java.lang.String org.hamcrest.beans.HasPropertyWithValueTest$BeanWithBug.getBroken()': \"bean failed\"", hasProperty("broken", anything()), new BeanWithBug()); }
/** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name whose value satisfies the specified matcher. * For example: * <pre>assertThat(myBean, hasProperty("foo", equalTo("bar"))</pre> * * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean */ public static <T> org.hamcrest.Matcher<T> hasProperty(java.lang.String propertyName, org.hamcrest.Matcher<?> valueMatcher) { return org.hamcrest.beans.HasPropertyWithValue.<T>hasProperty(propertyName, valueMatcher); }
@Test public void testWriteUnlockNotifiesListeners() throws MessageCodecException { ActiveInvokeContext<LockTransition> locker = newContext(); ActiveInvokeContext<LockTransition> waiter = newContext(); ClientDescriptor waiterDescriptor = () -> null; when(waiter.getClientDescriptor()).thenReturn(waiterDescriptor); entity.invokeActive(locker, LockMessaging.lock(WRITE)); entity.invokeActive(waiter, LockMessaging.lock(WRITE)); entity.invokeActive(locker, LockMessaging.unlock(WRITE)); verify(communicator).sendNoResponse(same(waiterDescriptor), argThat( HasPropertyWithValue.<EntityResponse>hasProperty("released", is(true)))); }
@Test public void testReadUnlockNotifiesListeners() throws MessageCodecException { ActiveInvokeContext<LockTransition> locker = newContext(); ActiveInvokeContext<LockTransition> waiter = newContext(); ClientDescriptor waiterDescriptor = () -> null; when(waiter.getClientDescriptor()).thenReturn(waiterDescriptor); entity.invokeActive(locker, LockMessaging.lock(READ)); entity.invokeActive(waiter, LockMessaging.lock(WRITE)); entity.invokeActive(locker, LockMessaging.unlock(READ)); verify(communicator).sendNoResponse(same(waiterDescriptor), argThat( HasPropertyWithValue.<EntityResponse>hasProperty("released", is(true)))); }
assertEquals(4, filterService.createFilterQuery().orderByFilterId().asc().list().size()); Assert.assertThat(filterService.createFilterQuery().orderByFilterId().asc().list(), contains(hasProperty("id", equalTo(sortedIds.get(0))), hasProperty("id", equalTo(sortedIds.get(1))), hasProperty("id", equalTo(sortedIds.get(2))), hasProperty("id", equalTo(sortedIds.get(3))))); contains(hasProperty("resourceType", equalTo(EntityTypes.TASK)), hasProperty("resourceType", equalTo(EntityTypes.TASK)), hasProperty("resourceType", equalTo(EntityTypes.TASK)), hasProperty("resourceType", equalTo(EntityTypes.TASK)))); contains(hasProperty("name", equalTo("a")), hasProperty("name", equalTo("b")), hasProperty("name", equalTo("c_")), hasProperty("name", equalTo("d")))); contains(hasProperty("owner", equalTo("a")), hasProperty("owner", equalTo("b")), hasProperty("owner", equalTo("c")), hasProperty("owner", equalTo("d")))); contains(hasProperty("id", equalTo(sortedIds.get(3))), hasProperty("id", equalTo(sortedIds.get(2))), hasProperty("id", equalTo(sortedIds.get(1))), hasProperty("id", equalTo(sortedIds.get(0))))); contains(hasProperty("resourceType", equalTo(EntityTypes.TASK)), hasProperty("resourceType", equalTo(EntityTypes.TASK)),
/** * Creates a matcher that matches when the examined object has a JavaBean property * with the specified name whose value satisfies the specified matcher. * For example: * <pre>assertThat(myBean, hasProperty("foo", equalTo("bar"))</pre> * * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean */ public static <T> org.hamcrest.Matcher<T> hasProperty(java.lang.String propertyName, org.hamcrest.Matcher<?> valueMatcher) { return org.hamcrest.beans.HasPropertyWithValue.hasProperty(propertyName, valueMatcher); }
@Test public void resolvesPluginWithNewestVersionOnDependency() throws Exception { final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(barPlugin, bazPlugin, fooPlugin); barPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(LATEST_BAZ_PLUGIN_DESCRIPTOR)).build()); bazPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).build()); latestBazPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(FOO_PLUGIN_DESCRIPTOR)).build()); when(artifactDescriptorFactory .create(argThat(hasProperty("absolutePath", endsWith(latestBazPlugin.getBundleDescriptor().getArtifactFileName()))), any(Optional.class))).thenReturn(latestBazPlugin); final List<ArtifactPluginDescriptor> resolvedPluginDescriptors = dependenciesResolver.resolve( emptySet(), pluginDescriptors, true); assertResolvedPlugins(resolvedPluginDescriptors, fooPlugin, bazPlugin, barPlugin); }