Revert "BAEL-2779 Guide to classgraph library"

This reverts commit af4e221f as it was asked to move it to libraries-2
This commit is contained in:
Denis Zhdanov 2019-04-22 08:13:32 +08:00
parent 7acfa36d59
commit 732a7413f4
9 changed files with 0 additions and 136 deletions

View File

@ -699,12 +699,6 @@
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>${classgraph.version}</version>
</dependency>
</dependencies>
<repositories>
@ -922,7 +916,6 @@
<mockftpserver.version>2.7.1</mockftpserver.version>
<commons-net.version>3.6</commons-net.version>
<reflections.version>0.9.11</reflections.version>
<classgraph.version>4.8.22</classgraph.version>
</properties>

View File

@ -1,78 +0,0 @@
package com.baeldung.classgraph;
import io.github.classgraph.*;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
public class ClassGraphUnitTest {
@Test
public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
doTest(result -> {
ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName());
assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName());
});
}
@Test
public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
doTest(result -> {
ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName());
});
}
@Test
public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() {
doTest(result -> {
ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> {
return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> {
AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName());
if (annotationInfo == null) {
return false;
}
return "web".equals(annotationInfo.getParameterValues().getValue("value"));
});
});
assertThat(filteredClassInfos)
.extracting(ClassInfo::getName)
.contains(MethodWithAnnotationParameterWeb.class.getName());
});
}
@Test
public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
doTest(result -> {
ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName());
assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName());
});
}
@Test
public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException {
try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) {
ResourceList resources = result.getResourcesWithExtension("config");
assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config");
assertThat(resources.get(0).getContentAsString()).isEqualTo("my data");
}
}
private void doTest(Consumer<ScanResult> checker) {
try (ScanResult result = new ClassGraph().enableAllInfo()
.whitelistPackages(getClass().getPackage().getName())
.scan())
{
checker.accept(result);
}
}
}

View File

@ -1,5 +0,0 @@
package com.baeldung.classgraph;
@TestAnnotation
public class ClassWithAnnotation {
}

View File

@ -1,7 +0,0 @@
package com.baeldung.classgraph;
public class FieldWithAnnotation {
@TestAnnotation
private String s;
}

View File

@ -1,8 +0,0 @@
package com.baeldung.classgraph;
public class MethodWithAnnotation {
@TestAnnotation
public void service() {
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.classgraph;
public class MethodWithAnnotationParameterDao {
@TestAnnotation("dao")
public void service() {
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.classgraph;
public class MethodWithAnnotationParameterWeb {
@TestAnnotation("web")
public void service() {
}
}

View File

@ -1,14 +0,0 @@
package com.baeldung.classgraph;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({TYPE, METHOD, FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
String value() default "";
}

View File

@ -1 +0,0 @@
my data