X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAnnotationsTest.java;h=4efbebbf4676263291d3b628e65288812843dbeb;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hp=853f8c090d2fa45b40ee78214139ecdf9c0188d9;hpb=608760751ce7fcf4e84e86a8b33d43bc1d9984d6;p=controller.git diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsTest.java index 853f8c090d..4efbebbf46 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -33,13 +33,10 @@ public class AnnotationsTest { private final String setSomethingString = "setSomething"; - private void assertRequireInterfaceAnnotationHasCorrectValue( - Class clazz, String methodName, - Set> inspectedInterfaces, - Class expectedValue) { + private static void assertRequireInterfaceAnnotationHasCorrectValue(final Class clazz, final String methodName, + final Set> inspectedInterfaces, final Class expectedValue) { Method setter = findMethod(clazz, methodName); - RequireInterface found = AttributeHolder - .findRequireInterfaceAnnotation(setter, inspectedInterfaces); + RequireInterface found = AttributeHolder.findRequireInterfaceAnnotation(setter, inspectedInterfaces); if (expectedValue == null) { assertNull(found); } else { @@ -48,22 +45,20 @@ public class AnnotationsTest { } } - private Method findMethod(Class clazz, String methodName) { + private static Method findMethod(final Class clazz, final String methodName) { Method setter; try { - setter = clazz.getMethod(methodName, - new Class[] { ObjectName.class }); - } catch (Exception e) { + setter = clazz.getMethod(methodName, new Class[] { ObjectName.class }); + } catch (final NoSuchMethodException e) { throw Throwables.propagate(e); } return setter; } - private void assertDescription(Class clazz, String methodName, - Set> exportedInterfaces, String expectedValue) { + private static void assertDescription(final Class clazz, final String methodName, + final Set> exportedInterfaces, final String expectedValue) { Method setter = findMethod(clazz, methodName); - String found = AttributeHolder.findDescription(setter, - exportedInterfaces); + String found = AttributeHolder.findDescription(setter, exportedInterfaces); if (expectedValue == null) { assertNull(found); } else { @@ -72,10 +67,9 @@ public class AnnotationsTest { } } - private void assertDescriptionOnClass(Class clazz, - Set> jmxInterfaces, String expectedValue) { - String found = AbstractDynamicWrapper.findDescription(clazz, - jmxInterfaces); + private static void assertDescriptionOnClass(final Class clazz, final Set> jmxInterfaces, + final String expectedValue) { + String found = AbstractDynamicWrapper.findDescription(clazz, jmxInterfaces); if (expectedValue == null) { assertNull(found); } else { @@ -84,27 +78,25 @@ public class AnnotationsTest { } } - private void assertNoDescriptionOnClass(Class clazz, - Set> jmxInterfaces) { - String found = AbstractDynamicWrapper.findDescription(clazz, - jmxInterfaces); + private static void assertNoDescriptionOnClass(final Class clazz, final Set> jmxInterfaces) { + String found = AbstractDynamicWrapper.findDescription(clazz, jmxInterfaces); assertTrue(found.isEmpty()); } static final String SIMPLE = "simple"; static final String SUBCLASS2 = "subclass2"; - @ServiceInterfaceAnnotation(value = SIMPLE, osgiRegistrationType = Executor.class, - namespace = "ns", revision = "rev", localName = SIMPLE) - static interface SimpleSI extends AbstractServiceInterface { - + @ServiceInterfaceAnnotation(value = SIMPLE, + osgiRegistrationType = Executor.class, + namespace = "ns", revision = "rev", localName = SIMPLE) + interface SimpleSI extends AbstractServiceInterface { } @Description("class") public static class SuperClass { @RequireInterface(SimpleSI.class) @Description("descr") - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } } @@ -115,12 +107,10 @@ public class AnnotationsTest { @Test public void testFindAnnotation_directly() throws Exception { - assertRequireInterfaceAnnotationHasCorrectValue(SuperClass.class, - setSomethingString, emptySetOfInterfaces(), SimpleSI.class); - assertDescription(SuperClass.class, setSomethingString, - emptySetOfInterfaces(), "descr"); - assertDescriptionOnClass(SuperClass.class, emptySetOfInterfaces(), - "class"); + assertRequireInterfaceAnnotationHasCorrectValue(SuperClass.class, setSomethingString, emptySetOfInterfaces(), + SimpleSI.class); + assertDescription(SuperClass.class, setSomethingString, emptySetOfInterfaces(), "descr"); + assertDescriptionOnClass(SuperClass.class, emptySetOfInterfaces(), "class"); } public static class SubClassWithout extends SuperClass { @@ -129,152 +119,121 @@ public class AnnotationsTest { @Test public void testFindAnnotation_subclassWithout() throws Exception { - assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithout.class, - setSomethingString, emptySetOfInterfaces(), SimpleSI.class); - assertDescription(SubClassWithout.class, setSomethingString, - emptySetOfInterfaces(), "descr"); - assertDescriptionOnClass(SuperClass.class, emptySetOfInterfaces(), - "class"); + assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithout.class, setSomethingString, + emptySetOfInterfaces(), SimpleSI.class); + assertDescription(SubClassWithout.class, setSomethingString, emptySetOfInterfaces(), "descr"); + assertDescriptionOnClass(SuperClass.class, emptySetOfInterfaces(), "class"); } public static class SubClassWithEmptyMethod extends SuperClass { @Override - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } } @Test public void testOverridingWithoutAnnotation() throws Exception { - assertRequireInterfaceAnnotationHasCorrectValue( - SubClassWithEmptyMethod.class, setSomethingString, + assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithEmptyMethod.class, setSomethingString, emptySetOfInterfaces(), SimpleSI.class); - assertDescription(SubClassWithEmptyMethod.class, setSomethingString, - emptySetOfInterfaces(), "descr"); - assertDescriptionOnClass(SubClassWithEmptyMethod.class, - emptySetOfInterfaces(), "class"); + assertDescription(SubClassWithEmptyMethod.class, setSomethingString, emptySetOfInterfaces(), "descr"); + assertDescriptionOnClass(SubClassWithEmptyMethod.class, emptySetOfInterfaces(), "class"); } - static interface SubSI extends SimpleSI { + interface SubSI extends SimpleSI { } - @ServiceInterfaceAnnotation(value = SUBCLASS2, osgiRegistrationType = ExecutorService.class, - namespace = "ns", revision = "rev", localName = SUBCLASS2) - - static interface SubSI2 extends SubSI { - + @ServiceInterfaceAnnotation(value = SUBCLASS2, + osgiRegistrationType = ExecutorService.class, namespace = "ns", revision = "rev", localName = SUBCLASS2) + interface SubSI2 extends SubSI { } public static class SubClassWithAnnotation extends SuperClass { @Override @RequireInterface(SubSI2.class) @Description("descr2") - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } } @Test public void testFindAnnotation_SubClassWithAnnotation() throws Exception { - assertDescription(SubClassWithAnnotation.class, setSomethingString, - emptySetOfInterfaces(), "descr2\ndescr"); + assertDescription(SubClassWithAnnotation.class, setSomethingString, emptySetOfInterfaces(), "descr2\ndescr"); try { - assertRequireInterfaceAnnotationHasCorrectValue( - SubClassWithAnnotation.class, setSomethingString, + assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithAnnotation.class, setSomethingString, emptySetOfInterfaces(), SubSI2.class); fail(); - } catch (IllegalStateException e) { - assertTrue( - e.getMessage(), - e.getMessage() - .startsWith("Error finding @RequireInterface. More than one value specified")); + } catch (final IllegalStateException e) { + assertTrue(e.getMessage(), + e.getMessage().startsWith("Error finding @RequireInterface. More than one value specified")); } } - public static interface HasSomeMethod { + public interface HasSomeMethod { void setSomething(ObjectName objectName); } - public static class SubClassWithoutMethodWithInterface extends SuperClass - implements HasSomeMethod { + public static class SubClassWithoutMethodWithInterface extends SuperClass implements HasSomeMethod { } @Test - public void testFindAnnotation_SubClassWithoutMethodWithInterface() - throws Exception { - assertRequireInterfaceAnnotationHasCorrectValue( - SubClassWithoutMethodWithInterface.class, setSomethingString, + public void testFindAnnotation_SubClassWithoutMethodWithInterface() throws Exception { + assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithoutMethodWithInterface.class, setSomethingString, emptySetOfInterfaces(), SimpleSI.class); - assertDescription(SubClassWithoutMethodWithInterface.class, - setSomethingString, emptySetOfInterfaces(), "descr"); + assertDescription(SubClassWithoutMethodWithInterface.class, setSomethingString, emptySetOfInterfaces(), + "descr"); } - static abstract class SuperClassWithInterface implements HasSomeMethod { + abstract static class SuperClassWithInterface implements HasSomeMethod { @Override @RequireInterface(SubSI2.class) @Description("descr") - public void setSomething(ObjectName objectName) { - + public void setSomething(final ObjectName objectName) { } } @Description("class") - public static class SubClassOfSuperClassWithInterface extends - SuperClassWithInterface { - + public static class SubClassOfSuperClassWithInterface extends SuperClassWithInterface { } @Test - public void testFindAnnotation_SubClassOfSuperClassWithInterface() - throws Exception { - assertRequireInterfaceAnnotationHasCorrectValue( - SubClassOfSuperClassWithInterface.class, setSomethingString, + public void testFindAnnotation_SubClassOfSuperClassWithInterface() throws Exception { + assertRequireInterfaceAnnotationHasCorrectValue(SubClassOfSuperClassWithInterface.class, setSomethingString, emptySetOfInterfaces(), SubSI2.class); - assertDescription(SubClassOfSuperClassWithInterface.class, - setSomethingString, emptySetOfInterfaces(), "descr"); - assertDescriptionOnClass(SubClassOfSuperClassWithInterface.class, - emptySetOfInterfaces(), "class"); + assertDescription(SubClassOfSuperClassWithInterface.class, setSomethingString, emptySetOfInterfaces(), "descr"); + assertDescriptionOnClass(SubClassOfSuperClassWithInterface.class, emptySetOfInterfaces(), "class"); } @Test public void testFindAnnotation2() throws Exception { - assertNoDescriptionOnClass(SuperClassWithInterface.class, - emptySetOfInterfaces()); + assertNoDescriptionOnClass(SuperClassWithInterface.class, emptySetOfInterfaces()); } @Description("class") - static interface HasSomeMethodWithAnnotations { - + interface HasSomeMethodWithAnnotations { @RequireInterface(SubSI2.class) @Description("descr") void setSomething(ObjectName objectName); } - static class HasSomeMethodWithAnnotationsImpl implements - HasSomeMethodWithAnnotations { + static class HasSomeMethodWithAnnotationsImpl implements HasSomeMethodWithAnnotations { @Override - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } - } @Test public void testHasSomeMethodWithAnnotationsImpl() { - HashSet> exportedInterfaces = Sets - .> newHashSet(HasSomeMethodWithAnnotations.class); - assertRequireInterfaceAnnotationHasCorrectValue( - HasSomeMethodWithAnnotationsImpl.class, setSomethingString, + HashSet> exportedInterfaces = Sets.>newHashSet(HasSomeMethodWithAnnotations.class); + assertRequireInterfaceAnnotationHasCorrectValue(HasSomeMethodWithAnnotationsImpl.class, setSomethingString, exportedInterfaces, SubSI2.class); - assertDescription(HasSomeMethodWithAnnotationsImpl.class, - setSomethingString, exportedInterfaces, "descr"); + assertDescription(HasSomeMethodWithAnnotationsImpl.class, setSomethingString, exportedInterfaces, "descr"); - assertDescriptionOnClass( - HasSomeMethodWithAnnotationsImpl.class, - new HashSet>(Arrays - .asList(HasSomeMethodWithAnnotations.class)), "class"); + assertDescriptionOnClass(HasSomeMethodWithAnnotationsImpl.class, + new HashSet<>(Arrays.asList(HasSomeMethodWithAnnotations.class)), "class"); } - }