@Test public void embeddedCandidatesAreDetected() throws IOException, ClassNotFoundException { // Validate nested type structure String nestedType = "org.springframework.context.index.sample.SampleEmbedded.Another$AnotherPublicCandidate"; Class<?> type = ClassUtils.forName(nestedType, getClass().getClassLoader()); assertThat(type, sameInstance(SampleEmbedded.Another.AnotherPublicCandidate.class)); CandidateComponentsMetadata metadata = compile(SampleEmbedded.class); assertThat(metadata, hasComponent( SampleEmbedded.PublicCandidate.class, Component.class)); assertThat(metadata, hasComponent(nestedType, Component.class.getName())); assertThat(metadata.getItems(), hasSize(2)); }
private void testSingleComponent(Class<?> target, Class<?>... stereotypes) { CandidateComponentsMetadata metadata = compile(target); assertThat(metadata, hasComponent(target, stereotypes)); assertThat(metadata.getItems(), hasSize(1)); }
private void testComponent(Class<?>... classes) { CandidateComponentsMetadata metadata = compile(classes); for (Class<?> c : classes) { assertThat(metadata, hasComponent(c, Component.class)); } assertThat(metadata.getItems(), hasSize(classes.length)); }
@Test public void packageInfo() { CandidateComponentsMetadata metadata = compile( "org/springframework/context/index/sample/jpa/package-info"); assertThat(metadata, hasComponent( "org.springframework.context.index.sample.jpa", "package-info")); }
@Test public void readWrite() throws IOException { CandidateComponentsMetadata metadata = new CandidateComponentsMetadata(); metadata.add(createItem("com.foo", "first", "second")); metadata.add(createItem("com.bar", "first")); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PropertiesMarshaller.write(metadata, outputStream); CandidateComponentsMetadata readMetadata = PropertiesMarshaller.read( new ByteArrayInputStream(outputStream.toByteArray())); assertThat(readMetadata, hasComponent("com.foo", "first", "second")); assertThat(readMetadata, hasComponent("com.bar", "first")); assertThat(readMetadata.getItems(), hasSize(2)); }