@Test public void repro() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ReproConfig.class); ctx.refresh(); Foo foo1 = ctx.getBean("foo1", Foo.class); Foo foo2 = ctx.getBean("foo2", Foo.class); ctx.getBean("packagePrivateBar", Bar.class); // <-- i.e. @Bean was registered assertThat(foo1.bar, not(is(foo2.bar))); // <-- i.e. @Bean *not* enhanced }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("Inner {")); assertThat(code, containsString("Inner2 extends Thread {")); assertThat(code, not(containsString("super();"))); assertThat(code, not(containsString("this$"))); assertThat(code, not(containsString("/* synthetic */"))); } }
private void doAssertions(ApplicationContext ctx) throws Exception { Foo foo = ctx.getBean(Foo.class); Bar bar1 = ctx.getBean(Bar.class); Bar bar2 = ctx.getBean(Bar.class); assertThat(bar1, is(bar2)); assertThat(bar1, is(foo.bar)); BarFactory barFactory1 = ctx.getBean(BarFactory.class); BarFactory barFactory2 = ctx.getBean(BarFactory.class); assertThat(barFactory1, is(barFactory2)); Bar bar3 = barFactory1.getObject(); Bar bar4 = barFactory1.getObject(); assertThat(bar3, is(not(bar4))); }
@Test public void shouldImplementHashCodeProperly() { final Collection<ConfigEntry> entries = new ArrayList<>(); entries.add(E1); assertThat(config.hashCode(), is(config.hashCode())); assertThat(config.hashCode(), is(new Config(config.entries()).hashCode())); assertThat(config.hashCode(), is(not(new Config(entries).hashCode()))); }
@Test public void testNoTransaction() { doInHibernate( this::sessionFactory, s -> { parent = s.load( Parent.class, parentID ); assertThat( parent, notNullValue() ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertFalse( isPropertyInitialized( parent, "children" ) ); } ); List children1 = parent.children; List children2 = parent.children; assertTrue( isPropertyInitialized( parent, "children" ) ); checkDirtyTracking( parent ); assertThat( children1, sameInstance( children2 ) ); assertThat( children1.size(), equalTo( CHILDREN_SIZE ) ); }
@Test public void shouldBuildImmutableUser() { LegacyCredential abc = LegacyCredential.forPassword( "123abc" ); LegacyCredential fruit = LegacyCredential.forPassword( "fruit" ); User u1 = new User.Builder( "Steve", abc ).build(); User u2 = new User.Builder( "Steve", fruit ) .withRequiredPasswordChange( true ) .withFlag( "nice_guy" ).build(); assertThat( u1, equalTo( u1 ) ); assertThat( u1, not( equalTo( u2 ) ) ); User u1AsU2 = u1.augment().withCredentials( fruit ) .withRequiredPasswordChange( true ) .withFlag( "nice_guy" ).build(); assertThat( u1, not( equalTo( u1AsU2 ))); assertThat( u2, equalTo( u1AsU2 )); User u2AsU1 = u2.augment().withCredentials( abc ) .withRequiredPasswordChange( false ) .withoutFlag( "nice_guy" ).build(); assertThat( u2, not( equalTo( u2AsU1 ))); assertThat( u1, equalTo( u2AsU1 )); assertThat( u1, not( equalTo( u2 ) ) ); } }
@SuppressWarnings("unchecked") @Test public void testXmlExampleIn107() throws Exception { javax.cache.Cache<Long, Product> productCache = cacheManager.getCache("productCache", Long.class, Product.class); assertThat(productCache, is(notNullValue())); Configuration<Long, Product> configuration = productCache.getConfiguration(Configuration.class); assertThat(configuration.getKeyType(), is(equalTo(Long.class))); assertThat(configuration.getValueType(), is(equalTo(Product.class))); Eh107ReverseConfiguration<Long, Product> eh107ReverseConfiguration = productCache.getConfiguration(Eh107ReverseConfiguration.class); assertThat(eh107ReverseConfiguration.isReadThrough(), is(true)); assertThat(eh107ReverseConfiguration.isWriteThrough(), is(true)); assertThat(eh107ReverseConfiguration.isStoreByValue(), is(true)); Product product = new Product(1L); productCache.put(1L, product); assertThat(productCache.get(1L).getId(), equalTo(product.getId())); product.setMutable("foo"); assertThat(productCache.get(1L).getMutable(), nullValue()); assertThat(productCache.get(1L), not(sameInstance(product))); javax.cache.Cache<Long, Customer> customerCache = cacheManager.getCache("customerCache", Long.class, Customer.class); assertThat(customerCache, is(notNullValue())); Configuration<Long, Customer> customerConfiguration = customerCache.getConfiguration(Configuration.class); assertThat(customerConfiguration.getKeyType(), is(equalTo(Long.class))); assertThat(customerConfiguration.getValueType(), is(equalTo(Customer.class))); Customer customer = new Customer(1L); customerCache.put(1L, customer); assertThat(customerCache.get(1L).getId(), equalTo(customer.getId())); }
@Test public void testCustomAsyncSelectorLocation() throws Exception { final File file = new File("target", "AsyncLoggerCustomSelectorLocationTest.log"); final Logger log = LogManager.getLogger("com.foo.Bar"); final Logger logIncludingLocation = LogManager.getLogger("com.include.location.Bar"); final String msg = "Async logger msg with location"; log.info(msg); logIncludingLocation.info(msg); CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread final BufferedReader reader = new BufferedReader(new FileReader(file)); final String firstLine = reader.readLine(); final String secondLine = reader.readLine(); final String thirdLine = reader.readLine(); reader.close(); file.delete(); // By default we expect location to be disabled assertThat(firstLine, containsString(msg)); assertThat(firstLine, not(containsString("testCustomAsyncSelectorLocation"))); // Configuration allows us to retain location assertThat(secondLine, containsString(msg)); assertThat(secondLine, containsString("testCustomAsyncSelectorLocation")); assertThat(thirdLine, nullValue()); }
private void assertMockMvcNotUsed(WebClient client, String url) throws Exception { assertThat(getResponse(client, url).getContentAsString(), not(equalTo("mvc"))); }
@SuppressWarnings("unchecked") private void assertCommonUserRefreshTokenProperties(OAuth2RefreshToken refreshToken) { assertThat(refreshToken, allOf(/*issuer(is(issuerUri)),*/ OAuth2RefreshTokenMatchers.username(is(tokenSupport.username)), OAuth2RefreshTokenMatchers.clientId(is(CLIENT_ID)), OAuth2RefreshTokenMatchers.subject(is(not(nullValue()))), OAuth2RefreshTokenMatchers.audience(is(tokenSupport.resourceIds)), OAuth2RefreshTokenMatchers.origin(is(OriginKeys.UAA)), OAuth2RefreshTokenMatchers.revocationSignature(is(not(nullValue()))), OAuth2RefreshTokenMatchers.jwtId(not(isEmptyString())), OAuth2RefreshTokenMatchers.issuedAt(is(greaterThan(0))), OAuth2RefreshTokenMatchers.expiry(is(greaterThan(0))) ) ); }
private void doTestModeCannotReplayTuples(KafkaSpoutConfig<String, String> spoutConfig) { KafkaSpout<String, String> spout = SpoutWithMockedConsumerSetupHelper.setupSpout(spoutConfig, conf, contextMock, collectorMock, consumerMock, partition); when(consumerMock.poll(anyLong())).thenReturn(new ConsumerRecords<>(Collections.singletonMap(partition, SpoutWithMockedConsumerSetupHelper.createRecords(partition, 0, 1)))); spout.nextTuple(); ArgumentCaptor<KafkaSpoutMessageId> msgIdCaptor = ArgumentCaptor.forClass(KafkaSpoutMessageId.class); verify(collectorMock).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), anyList(), msgIdCaptor.capture()); assertThat("Should have captured a message id", msgIdCaptor.getValue(), not(nullValue())); spout.fail(msgIdCaptor.getValue()); reset(consumerMock); when(consumerMock.poll(anyLong())).thenReturn(new ConsumerRecords<>(Collections.singletonMap(partition, SpoutWithMockedConsumerSetupHelper.createRecords(partition, 1, 1)))); spout.nextTuple(); //The consumer should not be seeking to retry the failed tuple, it should just be continuing from the current position verify(consumerMock, never()).seek(eq(partition), anyLong()); }
@Test void pathsWithDifferentLengthAreNotEqual() { Node node = createNode( 1337L ); Relationship relationship = createRelationship( 1337L, 7331L ); // Given Path firstPath = new PathImpl.Builder( node ).push( relationship ).build(); Path secondPath = new PathImpl.Builder( node ).push( relationship ).push( createRelationship( 1337L, 7331L ) ).build(); // When Then assertThat( firstPath, not( equalTo( secondPath ) ) ); assertThat( secondPath, not( equalTo( firstPath ) ) ); }
@Test public void withScopeResolver() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithScopeResolver.class); // custom scope annotation makes the bean prototype scoped. subsequent calls // to getBean should return distinct instances. assertThat(ctx.getBean(CustomScopeAnnotationBean.class), not(sameInstance(ctx.getBean(CustomScopeAnnotationBean.class)))); assertThat(ctx.containsBean("scannedComponent"), is(false)); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, not(containsString("synthetic"))); assertThat(code, not(containsString("AnonymousClass_"))); assertThat(code, containsString("f = 1;")); // assertThat(code, containsString("f = i;")); assertThat(code, not(containsString("Inner obj = ;"))); assertThat(code, containsString("Inner.this;")); } }
@Test public void testTransaction() { doInHibernate( this::sessionFactory, s -> { Parent parent = s.load( Parent.class, parentID ); assertThat( parent, notNullValue() ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertFalse( isPropertyInitialized( parent, "children" ) ); checkDirtyTracking( parent ); List children1 = parent.children; List children2 = parent.children; assertTrue( isPropertyInitialized( parent, "children" ) ); checkDirtyTracking( parent ); assertThat( children1, sameInstance( children2 ) ); assertThat( children1.size(), equalTo( CHILDREN_SIZE ) ); } ); }
@Test public void testAdd() throws Exception { Habit h1 = fixtures.createEmptyHabit(); assertFalse(h1.isArchived()); assertNull(h1.getId()); assertThat(habitList.indexOf(h1), equalTo(-1)); habitList.add(h1); assertNotNull(h1.getId()); assertThat(habitList.indexOf(h1), not(equalTo(-1))); assertThat(activeHabits.indexOf(h1), not(equalTo(-1))); }
@Test void shouldProvideUniquePorts() { PortRepository portRepository = mock( PortRepository.class ); PortProvider portProvider = new CoordinatingPortProvider( portRepository, port -> false ); when( portRepository.reserveNextPort( "foo" ) ).thenReturn( 40, 41 ); int port1 = portProvider.getNextFreePort( "foo" ); int port2 = portProvider.getNextFreePort( "foo" ); assertThat( port1, is( not( equalTo( port2 ) ) ) ); }
public static Pair<PointValue,PointValue> pointsWithSameValueOnSpaceFillingCurve( Config config ) { ConfiguredSpaceFillingCurveSettingsCache configuredCache = new ConfiguredSpaceFillingCurveSettingsCache( config ); SpaceFillingCurveSettings spaceFillingCurveSettings = configuredCache.forCRS( CoordinateReferenceSystem.WGS84 ); SpaceFillingCurve curve = spaceFillingCurveSettings.curve(); double[] origin = {0.0, 0.0}; Long spaceFillingCurveMapForOrigin = curve.derivedValueFor( origin ); double[] centerPointForOriginTile = curve.centerPointFor( spaceFillingCurveMapForOrigin ); PointValue originValue = Values.pointValue( CoordinateReferenceSystem.WGS84, origin ); PointValue centerPointValue = Values.pointValue( CoordinateReferenceSystem.WGS84, centerPointForOriginTile ); assertThat( "need non equal points for this test", origin, not( equalTo( centerPointValue ) ) ); return Pair.of( originValue, centerPointValue ); } }