diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-06-04 17:41:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-04 17:41:04 +0200 |
commit | 7f385ad3515184d0fa4099cc57e85a2060cfbd80 (patch) | |
tree | dacb621d2def964e2a001de927f28b3a18770f3d /container-jersey2/src/test/java/com/yahoo/container/servlet/jersey | |
parent | f16999e04017a5c38cdafed505498189cb24a66c (diff) |
Revert "Container-jersey2: Scala code replaced with Java"
Diffstat (limited to 'container-jersey2/src/test/java/com/yahoo/container/servlet/jersey')
2 files changed, 75 insertions, 75 deletions
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.java deleted file mode 100644 index a4f186c3c78..00000000000 --- a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.java +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.servlet.jersey.classvisitor; - -import com.yahoo.container.servlet.jersey.ResourceOrProviderClassVisitor; -import org.junit.Assert; -import org.junit.Test; -import org.objectweb.asm.ClassReader; - -import java.io.IOException; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class ResourceOrProviderClassVisitorTest { - @Test - public void resource_is_detected() throws IOException { - assert_is_accepted(Resource.class); - } - - @Test - public void provider_is_detected() throws IOException { - assert_is_accepted(Provider.class); - } - - @Test - public void inner_class_is_ignored() throws IOException { - assert_is_ignored(InnerClass.Inner.class); - } - - @Test - public void nested_public_class_is_detected() throws IOException { - assert_is_accepted(NestedClass.Nested.class); - } - - @Test - public void nested_non_public_class_is_ignored() throws IOException { - assert_is_ignored(NonPublicNestedClass.Nested.class); - } - - @Test - public void resource_with_multiple_annotations_is_detected() throws IOException { - assert_is_accepted(ResourceWithMultipleAnnotations.class); - } - - @Test - public void interface_is_ignored() throws IOException { - assert_is_ignored(InterfaceResource.class); - } - - @Test - public void abstract_class_is_ignored() throws IOException { - assert_is_ignored(AbstractResource.class); - } - - @Test - public void className_is_equal_to_getName() throws IOException { - assertThat(analyzeClass(Resource.class).getClassName(), is(Resource.class.getName())); - } - - private static void assert_is_accepted(Class<?> clazz) throws IOException { - Assert.assertTrue(className(clazz) + " was not accepted", analyzeClass(clazz).isJerseyClass()); - } - - private static void assert_is_ignored(Class<?> clazz) throws IOException { - Assert.assertFalse(className(clazz) + " was not ignored", analyzeClass(clazz).isJerseyClass()); - } - - private static ResourceOrProviderClassVisitor analyzeClass(Class<?> clazz) throws IOException { - return ResourceOrProviderClassVisitor.visit(new ClassReader(className(clazz))); - } - - private static String className(Class<?> clazz) { - return clazz.getName(); - } -} diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala new file mode 100644 index 00000000000..f20c5e02e62 --- /dev/null +++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala @@ -0,0 +1,75 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.servlet.jersey.classvisitor + +import com.yahoo.container.servlet.jersey.{ResourceOrProviderClassVisitor, classvisitor} +import org.junit.{Assert, Test} +import org.objectweb.asm.ClassReader + +import Assert.assertThat +import org.hamcrest.CoreMatchers.is + +import scala.reflect.ClassTag + +class ResourceOrProviderClassVisitorTest { + @Test + def resource_is_detected() { + assert_is_accepted[classvisitor.Resource] + } + + @Test + def provider_is_detected() { + assert_is_accepted[classvisitor.Provider] + } + + @Test + def inner_class_is_ignored() { + assert_is_ignored[classvisitor.InnerClass#Inner] + } + + @Test + def nested_public_class_is_detected() { + assert_is_accepted[classvisitor.NestedClass.Nested] + } + + @Test + def nested_non_public_class_is_ignored() { + assert_is_ignored[classvisitor.NonPublicNestedClass.Nested] + } + + @Test + def resource_with_multiple_annotations_is_detected() { + assert_is_accepted[classvisitor.ResourceWithMultipleAnnotations] + } + + def interface_is_ignored() { + assert_is_ignored[classvisitor.InterfaceResource] + } + + @Test + def abstract_class_is_ignored() { + assert_is_ignored[classvisitor.AbstractResource] + } + + @Test + def className_is_equal_to_getName() { + assertThat(analyzeClass[classvisitor.Resource].getClassName, is(classOf[classvisitor.Resource].getName)) + } + + def assert_is_accepted[T: ClassTag] { + Assert.assertTrue(className[T] + " was not accepted", + analyzeClass[T].isJerseyClass) + } + + def assert_is_ignored[T: ClassTag] { + Assert.assertFalse(className[T] + " was not ignored", + analyzeClass[T].isJerseyClass) + } + + def analyzeClass[T: ClassTag] = { + ResourceOrProviderClassVisitor.visit(new ClassReader(className[T])) + } + + def className[T: ClassTag] = implicitly[ClassTag[T]].runtimeClass.getName +} + + |