Refine search
@Test public void multiComponentScan() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MultiComponentScan.class); assertThat(ctx.getBean(CustomScopeAnnotationBean.class), not(sameInstance(ctx.getBean(CustomScopeAnnotationBean.class)))); assertThat(ctx.containsBean("scannedComponent"), is(true)); }
@Test public void recursion() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Level1Config.class); ctx.refresh(); // assert that all levels have been detected ctx.getBean(Level1Config.class); ctx.getBean(Level2Config.class); ctx.getBean(Level3Component.class); // assert that enhancement is working assertThat(ctx.getBean("level1Bean"), sameInstance(ctx.getBean("level1Bean"))); assertThat(ctx.getBean("level2Bean"), sameInstance(ctx.getBean("level2Bean"))); }
private void autowiredConfigClassBeanMethodsRespectScoping(Class<?>... configClasses) { ApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses); Config config = ctx.getBean(Config.class); TestBean testBean1 = config.autowiredConfig.testBean(); TestBean testBean2 = config.autowiredConfig.testBean(); assertThat("got two distinct instances of testBean when singleton scoping was expected", testBean1, sameInstance(testBean2)); }
@Test public void shouldGetTheCorrectSchemaForInt() { final Schema schema = SchemaUtil.getTypeSchema("INT"); assertThat(schema, sameInstance(Schema.OPTIONAL_INT32_SCHEMA)); }
@Test public void shouldReturnFutureForExistingSequenceNumber() { // Given: final CompletableFuture<Void> existingFuture = futureStore.getFutureForSequenceNumber(2); // When: final CompletableFuture<Void> newFuture = futureStore.getFutureForSequenceNumber(2); // Then: assertThat(newFuture, is(sameInstance(existingFuture))); }
@Test public void test() { AddJobMessage aj1 = factory.obtain(AddJobMessage.class); assertThat(aj1, isA(AddJobMessage.class)); CommandMessage cm1 = factory.obtain(CommandMessage.class); assertThat(cm1, isA(CommandMessage.class)); assertThat(factory.obtain(AddJobMessage.class), not(sameInstance(aj1))); assertThat(factory.obtain(CommandMessage.class), not(sameInstance(cm1))); factory.release(aj1); factory.release(cm1); assertThat(factory.obtain(AddJobMessage.class), sameInstance(aj1)); assertThat(factory.obtain(CommandMessage.class), sameInstance(cm1)); assertThat(factory.obtain(AddJobMessage.class), not(sameInstance(aj1))); assertThat(factory.obtain(CommandMessage.class), not(sameInstance(cm1))); } }
@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 getResponseAllMatches() throws Exception { when(matcher1.matches(request)).thenReturn(true); when(connection1.getResponse(request)).thenReturn(expectedResponse); WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); verify(matcher1).matches(request); verifyNoMoreInteractions(matcher2, connection2, defaultConnection); verify(connection1).getResponse(request); }
@Test public void shouldGetTheCorrectSchemaForLong() { final Schema schema = SchemaUtil.getTypeSchema("BIGINT"); assertThat(schema, sameInstance(Schema.OPTIONAL_INT64_SCHEMA)); }
@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 customConfigurationStereotype() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Config.class); ctx.refresh(); assertThat(ctx.containsBean("customName"), is(true)); TestBean a = ctx.getBean("a", TestBean.class); TestBean b = ctx.getBean("b", TestBean.class); assertThat(b, sameInstance(a.getSpouse())); }
@Test public void getResponseDefault() throws Exception { when(defaultConnection.getResponse(request)).thenReturn(expectedResponse); WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); verify(matcher1).matches(request); verify(matcher2).matches(request); verifyNoMoreInteractions(connection1, connection2); verify(defaultConnection).getResponse(request); }
@Test public void shouldGetTheCorrectSchemaForString() { final Schema schema = SchemaUtil.getTypeSchema("VARCHAR"); assertThat(schema, sameInstance(Schema.OPTIONAL_STRING_SCHEMA)); }
@Test public void shouldFilterBySubnetAndFindMultipleIpV6ResultsOrderedByMatchLength() throws Exception { final NetworkInterfaceStub stub = new NetworkInterfaceStub(); stub.add("ee80:0:0:0001:0:0:0:1/64"); final NetworkInterface ifc1 = stub.add("fe80:0:0:0:0:0:0:1/16"); final NetworkInterface ifc2 = stub.add("fe80:0001:0:0:0:0:0:1/32"); final NetworkInterface ifc3 = stub.add("fe80:0001:abcd:0:0:0:0:1/48"); final NetworkInterface[] filteredBySubnet = filterBySubnet(stub, getByName("fe80:0:0:0:0:0:0:0"), 16); assertThat(filteredBySubnet.length, is(3)); assertThat(filteredBySubnet[0], sameInstance(ifc3)); assertThat(filteredBySubnet[1], sameInstance(ifc2)); assertThat(filteredBySubnet[2], sameInstance(ifc1)); }
@Test public void getResponseSecondMatches() throws Exception { when(matcher2.matches(request)).thenReturn(true); when(connection2.getResponse(request)).thenReturn(expectedResponse); WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); verify(matcher1).matches(request); verify(matcher2).matches(request); verifyNoMoreInteractions(connection1, defaultConnection); verify(connection2).getResponse(request); }
@Test public void shouldGetTheCorrectSchemaForBoolean() { final Schema schema = SchemaUtil.getTypeSchema("BOOLEAN"); assertThat(schema, sameInstance(Schema.OPTIONAL_BOOLEAN_SCHEMA)); }
@Test public void shouldFilterBySubnetAndFindMultipleResultsOrderedByMatchLength() throws Exception { final NetworkInterfaceStub stub = new NetworkInterfaceStub(); stub.add("10.0.0.2/8"); final NetworkInterface ifc1 = stub.add("192.0.0.0/8"); final NetworkInterface ifc2 = stub.add("192.168.1.1/24"); final NetworkInterface ifc3 = stub.add("192.168.0.0/16"); final NetworkInterface[] filteredBySubnet = filterBySubnet(stub, getByName("192.0.0.0"), 8); assertThat(filteredBySubnet.length, is(3)); assertThat(filteredBySubnet[0], sameInstance(ifc2)); assertThat(filteredBySubnet[1], sameInstance(ifc3)); assertThat(filteredBySubnet[2], sameInstance(ifc1)); }
/** * Given: empty list of blocks for file * Expected: {@link Collections#EMPTY_LIST} */ @Test public void shouldReturnEmptyListWhenNoBlocksForFile() { List<CloneGroup> result = detect(null, new Block[0]); assertThat(result, sameInstance(Collections.EMPTY_LIST)); }
@Test public void shouldGetTheCorrectSchemaForDouble() { final Schema schema = SchemaUtil.getTypeSchema("DOUBLE"); assertThat(schema, sameInstance(Schema.OPTIONAL_FLOAT64_SCHEMA)); }
@Test public void handleFrameOpen() throws Exception { assertThat(this.session.isOpen(), is(false)); this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThat(this.session.isOpen(), is(true)); assertTrue(this.connectFuture.isDone()); assertThat(this.connectFuture.get(), sameInstance(this.session)); verify(this.handler).afterConnectionEstablished(this.session); verifyNoMoreInteractions(this.handler); }