From b82d944926ea3be16ac57a57dfbb214abf0bcdfd Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 13 Mar 2013 16:55:44 -0700 Subject: [PATCH] added a test case concerning a single extension implementing multiple extension points --- .../model/ExtensionTypeHierarchyTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/src/test/java/jenkins/model/ExtensionTypeHierarchyTest.java diff --git a/test/src/test/java/jenkins/model/ExtensionTypeHierarchyTest.java b/test/src/test/java/jenkins/model/ExtensionTypeHierarchyTest.java new file mode 100644 index 0000000000..2fb3edd76c --- /dev/null +++ b/test/src/test/java/jenkins/model/ExtensionTypeHierarchyTest.java @@ -0,0 +1,49 @@ +package jenkins.model; + +import hudson.ExtensionPoint; +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.TestExtension; + +import java.util.Arrays; +import java.util.Comparator; + +/** + * @author Kohsuke Kawaguchi + */ +public class ExtensionTypeHierarchyTest extends HudsonTestCase { + public static interface Animal extends ExtensionPoint {} + public static interface White extends ExtensionPoint {} + + @TestExtension + public static class Swan implements Animal, White {} + @TestExtension + public static class Crow implements Animal {} + + /** + * Swan is both white and animal, so a single swan instance gets listed to both. + */ + public void testSameExtensionCanImplementMultipleExtensionPoints() { + Animal[] animals = sort(jenkins.getExtensionList(Animal.class).toArray(new Animal[2])); + assertTrue(animals[0] instanceof Crow); + assertTrue(animals[1] instanceof Swan); + assertEquals(2, animals.length); + + White[] whites = sort(jenkins.getExtensionList(White.class).toArray(new White[1])); + assertTrue(whites[0] instanceof Swan); + assertEquals(1, whites.length); + + assertSame(animals[1],whites[0]); + } + + /** + * Sort by class name + */ + private T[] sort(T[] a) { + Arrays.sort(a,new Comparator() { + public int compare(T o1, T o2) { + return o1.getClass().getName().compareTo(o2.getClass().getName()); + } + }); + return a; + } +} -- GitLab