Refine search
@Test public void returnsReadableDescriptionFromToStringWhenInitialisedWithNull() { assertDescription("sameInstance(null)", sameInstance(null)); } }
@Test public void testSysPropReplace() { System.getProperties().setProperty("ehcache.match", Number.class.getName()); XmlConfiguration xmlConfig = new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/systemprops.xml")); assertThat(xmlConfig.getCacheConfigurations().get("bar").getKeyType(), sameInstance((Class)Number.class)); DefaultPersistenceConfiguration persistenceConfiguration = (DefaultPersistenceConfiguration)xmlConfig.getServiceCreationConfigurations().iterator().next(); assertThat(persistenceConfiguration.getRootDirectory(), is(new File(System.getProperty("user.home") + "/ehcache"))); }
@Test public void classSerialization() throws ClassNotFoundException { StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null); s.init(new TransientStateRepository()); Assert.assertThat(s.read(s.serialize(Enum.class)), IsSame.sameInstance(Enum.class)); Assert.assertThat(s.read(s.serialize(Dogs.Handel.getClass())), IsSame.sameInstance(Dogs.Handel.getClass())); Assert.assertThat(s.read(s.serialize(Dogs.Cassie.getClass())), IsSame.sameInstance(Dogs.Cassie.getClass())); Assert.assertThat(s.read(s.serialize(Dogs.Penny.getClass())), IsSame.sameInstance(Dogs.Penny.getClass())); }
@Override public void disposeResolvedParameters(ExecutionContext executionContext) { assertThat(executionContext, sameInstance(this.executionContext)); }
@Test public void testOneCacheConfigWithTemplate() throws Exception { final URL resource = XmlConfigurationTest.class.getResource("/configs/template-cache.xml"); XmlConfiguration xmlConfig = new XmlConfiguration(resource); assertThat(xmlConfig.getServiceCreationConfigurations(), hasSize(0)); assertThat(xmlConfig.getCacheConfigurations().keySet(), hasItem("bar")); assertThat(xmlConfig.getCacheConfigurations().get("bar").getServiceConfigurations(), IsCollectionContaining.hasItem(instanceOf(FooConfiguration.class))); assertThat(xmlConfig.getCacheConfigurations().get("bar").getKeyType(), sameInstance((Class) Number.class)); assertThat(xmlConfig.getCacheConfigurations().get("bar").getValueType(), sameInstance((Class)String.class)); final CacheConfigurationBuilder<String, String> example = xmlConfig.newCacheConfigurationBuilderFromTemplate("example", String.class, String.class, newResourcePoolsBuilder().heap(5, EntryUnit.ENTRIES)); assertThat(example.build().getExpiryPolicy(), equalTo((ExpiryPolicy) ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(30)))); try { xmlConfig.newCacheConfigurationBuilderFromTemplate("example", String.class, Number.class); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("CacheTemplate 'example' declares value type of java.lang.String. Provided: class java.lang.Number")); } try { xmlConfig.newCacheConfigurationBuilderFromTemplate("example", Number.class, String.class); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("CacheTemplate 'example' declares key type of java.lang.String. Provided: class java.lang.Number")); } assertThat(xmlConfig.newCacheConfigurationBuilderFromTemplate("bar", Object.class, Object.class), nullValue()); }
@Test public void testLoaderWriterBindOnInstanceConfigurationReturnsSelf() { DefaultResilienceStrategyConfiguration configuration = new DefaultResilienceStrategyConfiguration(mock(ResilienceStrategy.class)); assertThat(configuration.bind(null, null), sameInstance(configuration)); }
@Test public void returnsReadableDescriptionFromToString() { assertDescription("sameInstance(\"ARG\")", sameInstance("ARG")); }
@Test public void processorFailsAndfirstInterceptorThrowsExceptionAfter() throws Exception { when(processor.process(any())).thenThrow(new RuntimeException("Processor Error")); RuntimeException expectedException = new RuntimeException("Some Error"); ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") { @Override public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) { throw expectedException; } }); startFlowWithInterceptors(interceptor1); expected.expect(MessagingException.class); expected.expectCause(sameInstance(expectedException)); try { process(flow, eventBuilder(muleContext).message(Message.of("")).build()); } catch (MessagingException e) { assertThat(e.getInfo().getOrDefault(INFO_ALREADY_LOGGED_KEY, false), is(true)); throw e; } }
@Test public void testBindOnInstanceConfigurationReturnsSelf() { DefaultResilienceStrategyConfiguration configuration = new DefaultResilienceStrategyConfiguration(mock(ResilienceStrategy.class)); assertThat(configuration.bind(null), sameInstance(configuration)); }
@Test public void evaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { Object o1 = new Object(); Matcher<Object> matcher = sameInstance(o1); assertMatches(matcher, o1); assertDoesNotMatch(matcher, new Object()); }
@Test public void shouldUseDecoderProvidedInConstructor() { decoder = new Jsr283Encoder(); handler = new XmlHandler(destination, skipRootElement, parentPath, decoder, nameAttribute, typeAttribute, typeAttributeValue, scoping); assertThat(handler.destination, is(sameInstance(destination))); assertThat(handler.currentPath, is(sameInstance(parentPath))); assertThat(handler.skipFirstElement, is(skipRootElement)); assertThat(handler.decoder, is(sameInstance(decoder))); assertThat(handler.nameAttribute, is(sameInstance(nameAttribute))); }
@Test public void basicInstanceSerialization() throws ClassNotFoundException { StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null); s.init(new TransientStateRepository()); Assert.assertThat(s.read(s.serialize(People.Alice)), IsSame.sameInstance(People.Alice)); Assert.assertThat(s.read(s.serialize(People.Bob)), IsSame.sameInstance(People.Bob)); Assert.assertThat(s.read(s.serialize(People.Eve)), IsSame.sameInstance(People.Eve)); }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<String> matcher = sameInstance("irrelevant"); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); }
@Test public void shouldReturnParentForAncestorOfDegreeOne() { assertThat(path.getAncestor(1), is(sameInstance(parent))); assertThat(path.getParent(), is(sameInstance(parent))); }
@Test public void testDefaultTypesConfig() throws Exception { URL resource = XmlConfigurationTest.class.getResource("/configs/defaultTypes-cache.xml"); XmlConfiguration xmlConfig = new XmlConfiguration(resource); assertThat(xmlConfig.getCacheConfigurations().keySet(), hasItem("foo")); assertThat(xmlConfig.getCacheConfigurations().get("foo").getKeyType(), sameInstance((Class)Object.class)); assertThat(xmlConfig.getCacheConfigurations().get("foo").getValueType(), sameInstance((Class)Object.class)); assertThat(xmlConfig.getCacheConfigurations().keySet(), hasItem("bar")); assertThat(xmlConfig.getCacheConfigurations().get("bar").getKeyType(), sameInstance((Class)Number.class)); assertThat(xmlConfig.getCacheConfigurations().get("bar").getValueType(), sameInstance((Class)Object.class)); assertThat(xmlConfig.newCacheConfigurationBuilderFromTemplate("example", Object.class, Object.class, heap(10)), notNullValue()); //Allow the key/value to be assignable for xml configuration in case of type definition in template class assertThat(xmlConfig.newCacheConfigurationBuilderFromTemplate("example", Number.class, Object.class, heap(10)), notNullValue()); }
@Test public void testInteractionWithReusableParameterizedMessage() { final MutableLogEvent evt = new MutableLogEvent(); Message mementoMessageSecondInvocation = evt.memento(); assertThat(mementoMessage, sameInstance(mementoMessageSecondInvocation));
@Test public void shouldFindExistingWorkspaces() { assertThat(repository.getWorkspace("workspace1"), is(sameInstance(workspace1))); assertThat(repository.getWorkspace("workspace2"), is(sameInstance(workspace2))); }
@Test public void testPrimitiveClasses() throws ClassNotFoundException { StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null); s.init(new TransientStateRepository()); Class<?>[] out = (Class<?>[]) s.read(s.serialize(PRIMITIVE_CLASSES)); Assert.assertThat(out, IsNot.not(IsSame.sameInstance(PRIMITIVE_CLASSES))); Assert.assertThat(out, IsEqual.equalTo(PRIMITIVE_CLASSES)); }
@Test public void liftedActivityLightCycleAreEqualsWhenTheSourceIsTheSame() { final DefaultActivityLightCycle<Activity> lightCycle = new DefaultActivityLightCycle<>(); final ActivityLightCycle<Activity> lift1 = LightCycles.lift(lightCycle); final ActivityLightCycle<Activity> lift2 = LightCycles.lift(lightCycle); assertThat(lift1, not(sameInstance(lift2))); assertThat(lift1, equalTo(lift2)); }
@Test public void shouldReturnSuppliedTextEncoderWhenNonNullPassedToGetEncoder() { assertThat(factory.getDecoder(), is(sameInstance(ValueFactory.DEFAULT_DECODER))); assertThat(factory.getDecoder(null), is(sameInstance(ValueFactory.DEFAULT_DECODER))); assertThat(factory.getDecoder(CUSTOM_DECODER), is(sameInstance(CUSTOM_DECODER))); }