Refine search
private QuerySpecification getQuerySpecification(final Statement statement) { assertThat(statement, instanceOf(Query.class)); final Query query = (Query) statement; assertThat(query.getQueryBody(), instanceOf(QuerySpecification.class)); return (QuerySpecification) query.getQueryBody(); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> */ public static <T> org.hamcrest.Matcher<T> any(java.lang.Class<T> type) { return org.hamcrest.core.IsInstanceOf.<T>any(type); }
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } };
@Test public void shouldParseDynamicOperandFromStringContainingReferenceValueOfSelector() { DynamicOperand operand = parser.parseDynamicOperand(tokens("REFERENCE(tableA)"), typeSystem, mock(Source.class)); assertThat(operand, is(instanceOf(ReferenceValue.class))); ReferenceValue value = (ReferenceValue)operand; assertThat(value.selectorName(), is(selectorName("tableA"))); assertThat(value.getPropertyName(), is(nullValue())); }
@Test public void shouldParseNotPropertyExistanceFromPropertyNameWithSelectorNameAndPropertyNameFollowedByIsNull() { Constraint constraint = parser.parsePropertyExistance(tokens("tableA.property1 IS NULL"), typeSystem, mock(Source.class)); assertThat(constraint, is(instanceOf(Not.class))); Not not = (Not)constraint; assertThat(not.constraint(), is(instanceOf(PropertyExistence.class))); PropertyExistence p = (PropertyExistence)not.constraint(); assertThat(p.propertyName(), is("property1")); assertThat(p.selectorName(), is(selectorName("tableA"))); }
@Test public void testCallFunctionSync() throws Exception { ParseCloudCodeController controller = mockParseCloudCodeControllerWithResponse("result"); ParseCorePlugins.getInstance().registerCloudCodeController(controller); Map<String, Object> parameters = new HashMap<>(); parameters.put("key1", Arrays.asList(1, 2, 3)); parameters.put("key2", "value1"); Object result = ParseCloud.callFunction("name", parameters); verify(controller, times(1)).callFunctionInBackground(eq("name"), eq(parameters), isNull(String.class)); assertThat(result, instanceOf(String.class)); assertEquals("result", result); }
@Test public void testProvidedInstanceConstructed() { DefaultResilienceStrategyProviderConfiguration configuration = new DefaultResilienceStrategyProviderConfiguration(); DefaultResilienceStrategyProvider provider = new DefaultResilienceStrategyProvider(configuration); CacheConfiguration<?, ?> cacheConfiguration = mock(CacheConfiguration.class); when(cacheConfiguration.getServiceConfigurations()).thenReturn(Collections.singleton(new DefaultResilienceStrategyConfiguration(TestResilienceStrategy.class, "FooBar"))); ResilienceStrategy<?, ?> resilienceStrategy = provider.createResilienceStrategy("foo", cacheConfiguration, mock(RecoveryStore.class)); assertThat(resilienceStrategy, instanceOf(TestResilienceStrategy.class)); assertThat(((TestResilienceStrategy) resilienceStrategy).message, is("FooBar")); }
SimpleClusterTierClientEntity clientEntity2 = createClientEntity("testClearInvalidationUnblockedByDisconnection", false); StrongServerStoreProxy serverStoreProxy1 = new StrongServerStoreProxy("testClearInvalidationUnblockedByDisconnection", clientEntity1, mock(ServerCallback.class)); StrongServerStoreProxy serverStoreProxy2 = new StrongServerStoreProxy("testClearInvalidationUnblockedByDisconnection", clientEntity2, new ServerCallback() { @Override fail("expected RuntimeException"); } catch (RuntimeException re) { assertThat(re.getCause(), instanceOf(IllegalStateException.class));
@Test public void returnsMuleLoggerContextForInternalArtifactClassLoader() { ArtifactClassLoader serviceClassLoader = new MuleArtifactClassLoader("test", new ApplicationDescriptor("test"), new URL[0], this.getClass().getClassLoader(), mock(ClassLoaderLookupPolicy.class)); LoggerContext systemContext = selector.getContext("", this.getClass().getClassLoader(), true); LoggerContext serviceCtx = selector.getContext("", serviceClassLoader.getClassLoader(), true); assertThat(serviceCtx, instanceOf(MuleLoggerContext.class)); assertThat(serviceCtx, sameInstance(systemContext)); }
codeData.put("username", "test-username"); codeData.put(OriginKeys.ORIGIN, OriginKeys.UAA); when(codeStore.retrieveCode("the_secret_code", IdentityZoneHolder.get().getId())).thenReturn(new ExpiringCode("the_secret_code", new Timestamp(123), JsonUtils.writeValueAsString(codeData), ExpiringCodeType.AUTOLOGIN.name())); when(clientDetailsService.loadClientByClientId(eq(clientId), anyString())).thenReturn(new BaseClientDetails("test-client-details","","","","")); String zoneId = IdentityZoneHolder.get().getId(); when(userDatabase.retrieveUserById(eq("test-user-id"))) .thenReturn( new UaaUser("test-user-id", assertThat(authenticate, is(instanceOf(UaaAuthentication.class))); UaaAuthentication uaaAuthentication = (UaaAuthentication)authenticate; assertThat(uaaAuthentication.getPrincipal().getId(), is("test-user-id")); assertThat(uaaAuthentication.getPrincipal().getName(), is("test-username")); assertThat(uaaAuthentication.getPrincipal().getOrigin(), is(OriginKeys.UAA)); assertThat(uaaAuthentication.getDetails(), is(instanceOf(UaaAuthenticationDetails.class))); UaaAuthenticationDetails uaaAuthDetails = (UaaAuthenticationDetails)uaaAuthentication.getDetails(); assertThat(uaaAuthDetails.getClientId(), is(clientId));
private void assertResolved(Object resolvedValue, Object expected, VerificationMode expressionManagerVerificationMode) { assertThat(resolvedValue, instanceOf(String.class)); assertThat(resolvedValue, equalTo(expected)); verify(expressionManager, expressionManagerVerificationMode).openSession(any(BindingContext.class)); }
/** * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>. * <p/> * For example: * <pre>assertThat(cheese, isA(Cheddar.class))</pre> * instead of: * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre> * */ @Factory public static <T> Matcher<T> isA(Class<T> type) { final Matcher<T> typeMatcher = instanceOf(type); return is(typeMatcher); } }
@Test public void testTransactionalState() throws Exception { boolean shouldThrowException = resultMap.get(hasTransactionInContext).get(transactionConfig); Exception thrownException = null; CoreEvent result = null; if (hasTransactionInContext) { TransactionCoordination.getInstance().bindTransaction(mockTransaction); } ValidateTransactionalStateInterceptor<CoreEvent> interceptor = new ValidateTransactionalStateInterceptor<>(new ExecuteCallbackInterceptor<CoreEvent>(), transactionConfig, false); try { result = interceptor.execute(() -> mockMuleEvent, new ExecutionContext()); } catch (IllegalTransactionStateException e) { thrownException = e; } if (shouldThrowException) { assertThat(thrownException, notNullValue()); assertThat(thrownException, instanceOf(IllegalTransactionStateException.class)); } else { assertThat(result, is(mockMuleEvent)); } } }
/** * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>. * For example: * <pre>assertThat(cheese, isA(Cheddar.class))</pre> * instead of: * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre> * */ public static <T> Matcher<T> isA(Class<?> type) { return is(IsInstanceOf.<T>instanceOf(type)); } }
@Test public void testIsExtensible() { final UserManagedCacheConfiguration<String, Object, TestUserManagedCache<String, Object>> cfg = builder -> new UserManagedCacheBuilder<String, Object, TestUserManagedCache<String, Object>>(String.class, Object.class) { @Override TestUserManagedCache<String, Object> build(final ServiceLocator.DependencySet dependencySet) { return new TestUserManagedCache<>(); } }; assertNotNull(cfg); final TestUserManagedCache<String, Object> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(String.class, Object.class) .with(cfg).build(); assertThat(cache, notNullValue()); assertThat(cache, instanceOf(TestUserManagedCache.class)); }
@Test public void shouldParseDynamicOperandFromStringContainingReferenceValueWithWithOnlySelectorNameMatchingThatOfOneSelectorAsSource() { Source source = new NamedSelector(selectorName("tableA")); DynamicOperand operand = parser.parseDynamicOperand(tokens("REFERENCE(tableA) other"), typeSystem, source); assertThat(operand, is(instanceOf(ReferenceValue.class))); ReferenceValue value = (ReferenceValue)operand; assertThat(value.selectorName(), is(selectorName("tableA"))); assertThat(value.getPropertyName(), is(nullValue())); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> */ public static <T> org.hamcrest.Matcher<T> instanceOf(java.lang.Class<?> type) { return org.hamcrest.core.IsInstanceOf.<T>instanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a new instance of IsInstanceOf * * @param expectedClass The predicate evaluates to true for instances of this class * or one of its subclasses. */ public IsInstanceOf(Class<?> expectedClass) { this.expectedClass = expectedClass; this.matchableClass = matchableClass(expectedClass); }