diff options
author | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-30 17:04:41 +0100 |
---|---|---|
committer | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-30 17:04:41 +0100 |
commit | 17e253beea8436a2952ca5104fddde2699f042e9 (patch) | |
tree | eabb62f1f70b520d6b79a092b9d863ab1097c156 /abi-check-plugin | |
parent | 90a7dc030c71344e279fd29519526a8fd6ee26b1 (diff) |
Add more unit tests.
Diffstat (limited to 'abi-check-plugin')
4 files changed, 37 insertions, 13 deletions
diff --git a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java index cd9b545fe8d..345a0aa194e 100644 --- a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java +++ b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java @@ -126,7 +126,7 @@ public class AbiCheck extends AbstractMojo { } } - private static Map<String, JavaClassSignature> collectPublicAbiSignatures(Package pkg, + static Map<String, JavaClassSignature> collectPublicAbiSignatures(Package pkg, String publicApiAnnotation) throws IOException { Map<String, JavaClassSignature> signatures = new LinkedHashMap<>(); if (isPublicAbiPackage(pkg, publicApiAnnotation)) { diff --git a/abi-check-plugin/src/test/java/com/yahoo/abicheck/Public.java b/abi-check-plugin/src/test/java/com/yahoo/abicheck/Public.java index af39c999cd2..8e7410e032d 100644 --- a/abi-check-plugin/src/test/java/com/yahoo/abicheck/Public.java +++ b/abi-check-plugin/src/test/java/com/yahoo/abicheck/Public.java @@ -1,5 +1,12 @@ package com.yahoo.abicheck; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.PACKAGE}) public @interface Public { } diff --git a/abi-check-plugin/src/test/java/com/yahoo/abicheck/mojo/AbiCheckTest.java b/abi-check-plugin/src/test/java/com/yahoo/abicheck/mojo/AbiCheckTest.java index b8a96debebc..57fc607346c 100644 --- a/abi-check-plugin/src/test/java/com/yahoo/abicheck/mojo/AbiCheckTest.java +++ b/abi-check-plugin/src/test/java/com/yahoo/abicheck/mojo/AbiCheckTest.java @@ -1,24 +1,24 @@ -package com.yahoo.abicheck; +package com.yahoo.abicheck.mojo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.yahoo.abicheck.Public; import com.yahoo.abicheck.classtree.ClassFileTree; -import com.yahoo.abicheck.classtree.ClassFileTree.Package; -import com.yahoo.abicheck.mojo.AbiCheck; import com.yahoo.abicheck.signature.JavaClassSignature; import java.io.IOException; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.Test; +import root.Root; +import root.sub.Sub; public class AbiCheckTest { - @Test - public void testKukkuu() throws IOException { + private static ClassFileTree.Package buildClassFileTree() throws IOException { ClassFileTree.Package rootPkg = mock(ClassFileTree.Package.class); ClassFileTree.Package subPkg = mock(ClassFileTree.Package.class); @@ -31,16 +31,30 @@ public class AbiCheckTest { when(subPkg.getClassFiles()).thenReturn(Collections.singleton(subPkgClass)); when(rootPkgInfoClass.getName()).thenReturn("package-info.class"); + when(rootPkgInfoClass.getInputStream()) + .thenAnswer(invocation -> Root.class.getResourceAsStream("package-info.class")); + when(rootPkgClass.getName()).thenReturn("Root.class"); + when(rootPkgClass.getInputStream()) + .thenAnswer(invocation -> Root.class.getResourceAsStream("Root.class")); + when(subPkgClass.getName()).thenReturn("Sub.class"); + when(subPkgClass.getInputStream()) + .thenAnswer(invocation -> Sub.class.getResourceAsStream("Sub.class")); + + return rootPkg; + } + + @Test + public void testCollectPublicAbiSignatures() throws IOException { + ClassFileTree.Package rootPkg = buildClassFileTree(); Map<String, JavaClassSignature> signatures = AbiCheck - .collectPublicAbiSignatures(rootPkg, "com.yahoo.PublicApi"); + .collectPublicAbiSignatures(rootPkg, Public.class.getCanonicalName()); -// assertThat(signatures); - } + assertThat(signatures.size(), equalTo(1)); + JavaClassSignature rootSignature = signatures.get("root.Root"); - private static Collection<Package> buildClassFileTree() { - ClassFileTree.Package root = new ClassFileTree.Package(null, "com"); + // PublicSignatureCollectorTest verifies actual signatures, no need to duplicate here } } diff --git a/abi-check-plugin/src/test/java/root/package-info.java b/abi-check-plugin/src/test/java/root/package-info.java index 149630edd37..26f0f5c5a6f 100644 --- a/abi-check-plugin/src/test/java/root/package-info.java +++ b/abi-check-plugin/src/test/java/root/package-info.java @@ -1 +1,4 @@ -package root;
\ No newline at end of file +@Public +package root; + +import com.yahoo.abicheck.Public;
\ No newline at end of file |