From: Robert Varga Date: Wed, 3 May 2017 13:34:13 +0000 (+0200) Subject: Fix Eclipse warnings in config-manager X-Git-Tag: release/nitrogen~294 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=405c97ddf445b6057a2654545dd8072d28eedcce Fix Eclipse warnings in config-manager Change-Id: I0ed9bc52d4cf4e5ee7a4da8bd53355191326cba6 Signed-off-by: Robert Varga --- diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerInternal.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerInternal.java index 30183ebff3..11e5bfc63e 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerInternal.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerInternal.java @@ -27,7 +27,7 @@ interface ConfigTransactionControllerInternal extends /** * 1, Copy already committed modules to current transaction. * 2, Diff: compute added and removed factories from last run, then create new modules using - * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory)} + * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, BundleContext)} * and remove modules belonging to removed factories. */ void copyExistingModulesAndProcessFactoryDiff(Collection entries, List lastListOfFactories); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java index 4e89a653b8..85f0af7e54 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java @@ -160,25 +160,20 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe return "initial"; } }; - ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory = new ServiceReferenceTransactionRegistratorFactory(){ + ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory = () -> new ServiceReferenceRegistrator() { @Override - public ServiceReferenceRegistrator create() { - return new ServiceReferenceRegistrator() { - @Override - public String getNullableTransactionName() { - throw new UnsupportedOperationException(); - } - - @Override - public ServiceReferenceJMXRegistration registerMBean(final ServiceReferenceMXBeanImpl object, final ObjectName on) throws InstanceAlreadyExistsException { - throw new UnsupportedOperationException(); - } - - @Override - public void close() { - - } - }; + public String getNullableTransactionName() { + throw new UnsupportedOperationException(); + } + + @Override + public ServiceReferenceJMXRegistration registerMBean(final ServiceReferenceMXBeanImpl object, final ObjectName on) throws InstanceAlreadyExistsException { + throw new UnsupportedOperationException(); + } + + @Override + public void close() { + } }; return new ServiceReferenceRegistryImpl(Collections.emptyMap(), lookupRegistry, @@ -351,7 +346,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe public synchronized void checkServiceReferenceExists(final ObjectName objectName) throws InstanceNotFoundException { String actualTransactionName = ObjectNameUtil.getTransactionName(objectName); String expectedTransactionName = serviceReferenceRegistrator.getNullableTransactionName(); - if (writable && actualTransactionName == null || (writable && !actualTransactionName.equals(expectedTransactionName))) { + if (writable && actualTransactionName == null || writable && !actualTransactionName.equals(expectedTransactionName)) { throw new IllegalArgumentException("Mismatched transaction name in " + objectName); } String serviceQName = ObjectNameUtil.getServiceQName(objectName); @@ -442,9 +437,9 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe if (writable) { return ObjectNameUtil.createTransactionServiceON(serviceReferenceRegistrator.getNullableTransactionName(), serviceReference.getServiceInterfaceQName(), serviceReference.getRefName()); - } else { - return ObjectNameUtil.createReadOnlyServiceON(serviceReference.getServiceInterfaceQName(), serviceReference.getRefName()); } + + return ObjectNameUtil.createReadOnlyServiceON(serviceReference.getServiceInterfaceQName(), serviceReference.getRefName()); } @Override diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java index eb3676cceb..8fa7fdfdde 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java @@ -143,9 +143,6 @@ final class DependencyResolverImpl implements DependencyResolver, return translatedDependentReadOnlyON; } - /** - * {@inheritDoc} - */ //TODO: check for cycles @Override public T resolveInstance(final Class expectedType, final ObjectName dependentReadOnlyON, @@ -158,20 +155,16 @@ final class DependencyResolverImpl implements DependencyResolver, final AutoCloseable instance = module.getInstance(); if (instance == null) { final String message = String.format( - "Error while %s resolving instance %s. getInstance() returned null. " - + "Expected type %s , attribute %s", this.name, - module.getIdentifier(), expectedType, jmxAttribute - ); + "Error while %s resolving instance %s. getInstance() returned null. Expected type %s, attribute %s", + this.name, module.getIdentifier(), expectedType, jmxAttribute); throw new JmxAttributeValidationException(message, jmxAttribute); } try { return expectedType.cast(instance); } catch (final ClassCastException e) { final String message = String.format( - "Instance cannot be cast to expected type. Instance class is %s , " - + "expected type %s , attribute %s", - instance.getClass(), expectedType, jmxAttribute - ); + "Instance cannot be cast to expected type. Instance class is %s, expected type %s , attribute %s", + instance.getClass(), expectedType, jmxAttribute); throw new JmxAttributeValidationException(message, e, jmxAttribute); } } @@ -197,9 +190,10 @@ final class DependencyResolverImpl implements DependencyResolver, final Module currentModule = resolveModuleInstance(objectName, jmxAttribute); final ModuleIdentifier identifier = currentModule.getIdentifier(); - final ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = this.modulesHolder.findModuleInternalTransactionalInfo(identifier); + final ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = this.modulesHolder + .findModuleInternalTransactionalInfo(identifier); - if(moduleInternalTransactionalInfo.hasOldModule()) { + if (moduleInternalTransactionalInfo.hasOldModule()) { final Module oldModule = moduleInternalTransactionalInfo.getOldInternalInfo().getReadableModule().getModule(); return currentModule.canReuse(oldModule); } @@ -207,7 +201,8 @@ final class DependencyResolverImpl implements DependencyResolver, } @Override - public Class resolveIdentity(final IdentityAttributeRef identityRef, final Class expectedBaseClass) { + public Class resolveIdentity(final IdentityAttributeRef identityRef, + final Class expectedBaseClass) { final QName qName = QName.create(identityRef.getqNameOfIdentity()); final Class deserialized = this.bindingContextProvider.getBindingContext().getIdentityClass(qName); if (deserialized == null) { @@ -216,15 +211,15 @@ final class DependencyResolverImpl implements DependencyResolver, } if (expectedBaseClass.isAssignableFrom(deserialized)) { return (Class) deserialized; - } else { - LOG.error("Cannot resolve class of identity {} : deserialized class {} is not a subclass of {}.", - identityRef, deserialized, expectedBaseClass); - throw new IllegalArgumentException("Deserialized identity " + deserialized + " cannot be cast to " + expectedBaseClass); } + LOG.error("Cannot resolve class of identity {} : deserialized class {} is not a subclass of {}.", identityRef, + deserialized, expectedBaseClass); + throw new IllegalArgumentException("Deserialized identity " + deserialized + " cannot be cast to " + expectedBaseClass); } @Override - public void validateIdentity(final IdentityAttributeRef identityRef, final Class expectedBaseClass, final JmxAttribute jmxAttribute) { + public void validateIdentity(final IdentityAttributeRef identityRef, + final Class expectedBaseClass, final JmxAttribute jmxAttribute) { try { resolveIdentity(identityRef, expectedBaseClass); } catch (final Exception e) { @@ -281,7 +276,7 @@ final class DependencyResolverImpl implements DependencyResolver, chainForDetectingCycles2); dependentDRI.maxDependencyDepth = subDepth; } - if ((subDepth + 1) > maxDepth) { + if (subDepth + 1 > maxDepth) { maxDepth = subDepth + 1; } } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java index 23a4424a0b..25f7e2de9f 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java @@ -302,9 +302,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { String transactionName = ObjectNameUtil.getTransactionName(on); if (transactionName != null) { return ObjectNameUtil.withoutTransactionName(on); - } else { - return on; } + + return on; } @Override diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java index e8639d5881..0cbbbab912 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java @@ -22,14 +22,12 @@ import org.slf4j.LoggerFactory; /** * Retrieves list of currently registered Module Factories using bundlecontext. */ -public class BundleContextBackedModuleFactoriesResolver implements - ModuleFactoriesResolver { - private static final Logger LOG = LoggerFactory - .getLogger(BundleContextBackedModuleFactoriesResolver.class); +public class BundleContextBackedModuleFactoriesResolver implements ModuleFactoriesResolver { + private static final Logger LOG = LoggerFactory.getLogger(BundleContextBackedModuleFactoriesResolver.class); private final BundleContext bundleContext; public BundleContextBackedModuleFactoriesResolver( - BundleContext bundleContext) { + final BundleContext bundleContext) { this.bundleContext = bundleContext; } @@ -37,8 +35,7 @@ public class BundleContextBackedModuleFactoriesResolver implements public Map> getAllFactories() { Collection> serviceReferences; try { - serviceReferences = bundleContext.getServiceReferences( - ModuleFactory.class, null); + serviceReferences = bundleContext.getServiceReferences(ModuleFactory.class, null); } catch (InvalidSyntaxException e) { throw new IllegalStateException(e); } @@ -49,7 +46,7 @@ public class BundleContextBackedModuleFactoriesResolver implements // returned by a ServiceFactory does not // implement the classes under which it was registered or the // ServiceFactory threw an exception. - if(factory == null) { + if (factory == null) { throw new NullPointerException("ServiceReference of class" + serviceReference.getClass() + "not found."); } @@ -65,15 +62,15 @@ public class BundleContextBackedModuleFactoriesResolver implements Map.Entry conflicting = result.get(moduleName); if (conflicting != null) { - String error = String - .format("Module name is not unique. Found two conflicting factories with same name '%s': '%s' '%s'", - moduleName, conflicting.getKey(), factory); + String error = String.format( + "Module name is not unique. Found two conflicting factories with same name '%s': '%s' '%s'", + moduleName, conflicting.getKey(), factory); LOG.error(error); throw new IllegalArgumentException(error); - } else { - result.put(moduleName, new AbstractMap.SimpleImmutableEntry<>(factory, - serviceReference.getBundle().getBundleContext())); } + + result.put(moduleName, new AbstractMap.SimpleImmutableEntry<>(factory, + serviceReference.getBundle().getBundleContext())); } return result; } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java index 1d8c3bbc30..a5d77eabe0 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java @@ -74,18 +74,11 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl final ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker( blankTransactionServiceTracker); - final boolean scanResolvedBundlesForModuleInfo = true; - BundleTracker>> moduleInfoResolvedBundleTracker = null; - ExtensibleBundleTracker moduleFactoryBundleTracker; - if(scanResolvedBundlesForModuleInfo) { - moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | - Bundle.STOPPING | Bundle.ACTIVE, moduleInfoBundleTracker); - moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, moduleFactoryTracker); - } else { - moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, - moduleFactoryTracker, moduleInfoBundleTracker); - } - + BundleTracker>> moduleInfoResolvedBundleTracker = + new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, + moduleInfoBundleTracker); + ExtensibleBundleTracker moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, + moduleFactoryTracker); moduleInfoBundleTracker.open(moduleInfoResolvedBundleTracker); // start extensible tracker @@ -156,7 +149,7 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl // If the system bundle (id 0) is stopping close the ConfigRegistry so it destroys all modules. On // shutdown the system bundle is stopped first. - if((event.getBundle().getBundleId() == SYSTEM_BUNDLE_ID) && (event.getType() == BundleEvent.STOPPING)) { + if(event.getBundle().getBundleId() == SYSTEM_BUNDLE_ID && event.getType() == BundleEvent.STOPPING) { this.configRegistry.close(); } } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java index 919aeda5ae..deb202cf00 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java @@ -12,13 +12,12 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; + import com.google.common.base.Preconditions; import java.io.File; import java.io.IOException; import java.lang.management.ManagementFactory; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Dictionary; import java.util.LinkedList; @@ -144,7 +143,7 @@ public abstract class AbstractConfigTest extends AbstractLockedPlatformMBeanServ doNothing().when(this.mockedServiceRegistration).unregister(); final RegisterServiceAnswer answer = new RegisterServiceAnswer(); doAnswer(answer).when(this.mockedContext).registerService(Matchers.any(), any(), Matchers.>any()); - doAnswer(answer).when(this.mockedContext).registerService(Matchers.any(), any(), Matchers.>any()); + doAnswer(answer).when(this.mockedContext).registerService(Matchers.>any(), any(), Matchers.>any()); } @After @@ -262,20 +261,17 @@ public abstract class AbstractConfigTest extends AbstractLockedPlatformMBeanServ protected T rethrowCause(final T innerObject) { @SuppressWarnings("unchecked") final T proxy = (T)Proxy.newProxyInstance(innerObject.getClass().getClassLoader(), - innerObject.getClass().getInterfaces(), new InvocationHandler() { - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { - try { - return method.invoke(innerObject, args); - } catch (final InvocationTargetException e) { - try { - throw e.getTargetException(); - } catch (final RuntimeMBeanException e2) { - throw e2.getTargetException(); - } - } + innerObject.getClass().getInterfaces(), (proxy1, method, args) -> { + try { + return method.invoke(innerObject, args); + } catch (final InvocationTargetException e) { + try { + throw e.getTargetException(); + } catch (final RuntimeMBeanException e2) { + throw e2.getTargetException(); } } + } ); return proxy; } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImplLookupTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImplLookupTest.java index 5fbe8688e0..eabf8ec520 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImplLookupTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImplLookupTest.java @@ -85,16 +85,15 @@ public class ConfigRegistryImplLookupTest extends } - private void registerModuleBean(TestingRuntimeBean testingRuntimeBean, - BaseJMXRegistrator baseJMXRegistrator, ObjectName objectName) + private static void registerModuleBean(final TestingRuntimeBean testingRuntimeBean, + final BaseJMXRegistrator baseJMXRegistrator, final ObjectName objectName) throws InstanceAlreadyExistsException { baseJMXRegistrator.createModuleJMXRegistrator().registerMBean( testingRuntimeBean, objectName); } - private void registerRuntimeBean(RuntimeBean object, - BaseJMXRegistrator baseJMXRegistrator, ObjectName runtimeON) - throws InstanceAlreadyExistsException { + private static void registerRuntimeBean(final RuntimeBean object, final BaseJMXRegistrator baseJMXRegistrator, + final ObjectName runtimeON) throws InstanceAlreadyExistsException { String factoryName = ObjectNameUtil.getFactoryName(runtimeON); String instanceName = ObjectNameUtil.getInstanceName(runtimeON); Map properties = ObjectNameUtil diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java index c7b98a14d0..9263e42948 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java @@ -61,12 +61,9 @@ public class ConfigTransactionControllerImplTest extends transactionsMBeanServer = MBeanServerFactory.createMBeanServer(); Map> currentlyRegisteredFactories = new HashMap<>(); - ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry(new TransactionIdentifier(transactionName123), new TransactionJMXRegistratorFactory() { - @Override - public TransactionJMXRegistrator create() { - return baseJMXRegistrator.createTransactionJMXRegistrator(transactionName123); - } - }, currentlyRegisteredFactories); + ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry( + new TransactionIdentifier(transactionName123), () -> + baseJMXRegistrator.createTransactionJMXRegistrator(transactionName123), currentlyRegisteredFactories); SearchableServiceReferenceWritableRegistry writableRegistry = ServiceReferenceRegistryImpl.createSRWritableRegistry( ServiceReferenceRegistryImpl.createInitialSRLookupRegistry(), txLookupRegistry, currentlyRegisteredFactories); @@ -98,8 +95,6 @@ public class ConfigTransactionControllerImplTest extends /** * Tests if lookup method returns all beans with defined transaction name - * - * @throws Exception */ @Test public void testLookupConfigBeans() { diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImplTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImplTest.java index 27515cf969..9b9a92270a 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImplTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImplTest.java @@ -85,7 +85,7 @@ public class ServiceReferenceRegistryImplTest extends AbstractParallelAPSPTest { assertEquals(1, registrations.size()); RegistrationHolder record = registrations.get(0); assertEquals(TestingThreadPoolIfc.class, record.clazz); - assertEquals(ImmutableMap.of("name","ref"), (Map) record.props); + assertEquals(ImmutableMap.of("name","ref"), record.props); // switch reference to scheduled ConfigTransactionJMXClient transaction2 = configRegistryClient.createTransaction(); @@ -118,7 +118,7 @@ public class ServiceReferenceRegistryImplTest extends AbstractParallelAPSPTest { assertTrue(serviceMapping.isEmpty()); } - private void checkApspThreadCount(int fixedNrOfThreads) throws MBeanException, AttributeNotFoundException, + private void checkApspThreadCount(final int fixedNrOfThreads) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { ObjectName apspON = ObjectNameUtil.createReadOnlyModuleON(TestingParallelAPSPModuleFactory.NAME, apsp1); assertEquals(fixedNrOfThreads, platformMBeanServer.getAttribute(apspON, "MaxNumberOfThreads")); diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java index 63a33a3031..20a127ed23 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java @@ -85,16 +85,16 @@ public class DependencyResolverManagerTest extends AbstractLockedPlatformMBeanSe * Simulate dependentResolver resolving its dependency identified by * dependentName. */ - private void declareDependency(DependencyResolverImpl dependerResolver, - ModuleIdentifier dependentName) { + private static void declareDependency(final DependencyResolverImpl dependerResolver, + final ModuleIdentifier dependentName) { JmxAttribute dummyAttribute = new JmxAttribute("dummy"); dependerResolver.resolveInstance(Object.class, ObjectNameUtil.createReadOnlyModuleON(dependentName), dummyAttribute); } - private static void mockGetInstance(DependencyResolverManager tested, - ModuleIdentifier moduleIdentifier) { + private static void mockGetInstance(final DependencyResolverManager tested, + final ModuleIdentifier moduleIdentifier) { ModuleFactory moduleFactory = mock(ModuleFactory.class); ModuleInternalInfo maybeOldInternalInfo = null; 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 029b347cca..018fea86ed 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 @@ -33,10 +33,8 @@ 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); @@ -48,19 +46,18 @@ 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 }); + setter = clazz.getMethod(methodName, new Class[] { ObjectName.class }); } catch (Exception 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); @@ -72,10 +69,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,10 +80,8 @@ 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()); } @@ -104,7 +98,7 @@ public class AnnotationsTest { public static class SuperClass { @RequireInterface(SimpleSI.class) @Description("descr") - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } } @@ -139,7 +133,7 @@ public class AnnotationsTest { public static class SubClassWithEmptyMethod extends SuperClass { @Override - public void setSomething(ObjectName objectName) { + public void setSomething(final ObjectName objectName) { } } @@ -169,25 +163,21 @@ public class AnnotationsTest { @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, - emptySetOfInterfaces(), SubSI2.class); + 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")); + assertTrue(e.getMessage(), + e.getMessage().startsWith("Error finding @RequireInterface. More than one value specified")); } } @@ -195,8 +185,7 @@ public class AnnotationsTest { void setSomething(ObjectName objectName); } - public static class SubClassWithoutMethodWithInterface extends SuperClass - implements HasSomeMethod { + public static class SubClassWithoutMethodWithInterface extends SuperClass implements HasSomeMethod { } @@ -214,14 +203,13 @@ public class AnnotationsTest { @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 { } @@ -239,41 +227,32 @@ public class AnnotationsTest { @Test public void testFindAnnotation2() throws Exception { - assertNoDescriptionOnClass(SuperClassWithInterface.class, - emptySetOfInterfaces()); + assertNoDescriptionOnClass(SuperClassWithInterface.class, emptySetOfInterfaces()); } @Description("class") 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, + 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"); } - } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTrackerTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTrackerTest.java index 47b6d100c9..7d426be662 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTrackerTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTrackerTest.java @@ -13,6 +13,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; + import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; import javax.management.ObjectName; @@ -70,7 +71,7 @@ public class BlankTransactionServiceTrackerTest { verify(blankTx, times(maxAttempts)).hit(); } - private ServiceReference getMockServiceReference() { + private static ServiceReference getMockServiceReference() { return mock(ServiceReference.class); } } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolverTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolverTest.java index 0545fbf65f..72d6526225 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolverTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolverTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; + import com.google.common.collect.Lists; import java.util.Map; import org.junit.Before; @@ -49,7 +50,7 @@ public class BundleContextBackedModuleFactoriesResolverTest { resolver = new BundleContextBackedModuleFactoriesResolver(bundleContext); } - private ModuleFactory getMockFactory(final String name) { + private static ModuleFactory getMockFactory(final String name) { ModuleFactory mock = mock(ModuleFactory.class); doReturn(name).when(mock).toString(); doReturn(name).when(mock).getImplementationName(); diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtilTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtilTest.java index 5a04594c14..77d48f6ac5 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtilTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtilTest.java @@ -56,7 +56,7 @@ public class OsgiRegistrationUtilTest { verify(sTracker).close(); } - private ServiceRegistration mockServiceRegistration() { + private static ServiceRegistration mockServiceRegistration() { ServiceRegistration mock = mock(ServiceRegistration.class); doNothing().when(mock).unregister(); return mock; diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java index 19e6ef3b78..451980c3ef 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java @@ -72,21 +72,21 @@ public class RuntimeBeanTest extends AbstractScheduledTest { private void checkRuntimeBeans() throws Exception { // check runtime bean - on 2 places - for (ObjectName on : allObjectNames) + for (ObjectName on : allObjectNames) { checkRuntimeBean(on); + } } - private void checkRuntimeBean(ObjectName on) throws Exception { - assertEquals(0, - platformMBeanServer.getAttribute(on, "ActualNumberOfThreads")); + private static void checkRuntimeBean(final ObjectName on) throws Exception { + assertEquals(0, platformMBeanServer.getAttribute(on, "ActualNumberOfThreads")); } - private void checkRuntimeBeanDoesNotExist(ObjectName on) throws Exception { + private static void checkRuntimeBeanDoesNotExist(final ObjectName on) throws Exception { try { checkRuntimeBean(on); fail(); } catch (InstanceNotFoundException e) { - + // No-op } } @@ -149,8 +149,9 @@ public class RuntimeBeanTest extends AbstractScheduledTest { configTransaction.destroyModule(ObjectNameUtil .createTransactionModuleON(configTransaction.getTransactionName(), createdConfigBean)); configTransaction.commit(); - for (ObjectName on : allObjectNames) + for (ObjectName on : allObjectNames) { checkRuntimeBeanDoesNotExist(on); + } } } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java index a15839d2d5..df08f894c9 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java @@ -38,6 +38,7 @@ import org.opendaylight.controller.config.manager.impl.factoriesresolver.Hardcod import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory; +import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc; import org.opendaylight.controller.config.util.ConfigTransactionClient; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; @@ -95,7 +96,7 @@ public class SimpleConfigurationTest extends AbstractConfigTest { } static ObjectName createFixedThreadPool( - ConfigTransactionJMXClient transaction) + final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException, InstanceNotFoundException { transaction.assertVersion(0, 1); @@ -130,7 +131,7 @@ public class SimpleConfigurationTest extends AbstractConfigTest { } - private void testValidation(ConfigTransactionClient transaction) + private static void testValidation(final ConfigTransactionClient transaction) throws InstanceAlreadyExistsException, ReflectionException, InstanceNotFoundException, MBeanException, ConflictingVersionException { ObjectName fixed1names = transaction.createModule( @@ -276,8 +277,8 @@ public class SimpleConfigurationTest extends AbstractConfigTest { checkThreadPools(1, numberOfThreads2); } - private void checkThreadPools(int expectedTotalNumberOfExecutors, - int expectedNumberOfThreadsInLastExecutor) { + private static void checkThreadPools(final int expectedTotalNumberOfExecutors, + final int expectedNumberOfThreadsInLastExecutor) { assertEquals(expectedTotalNumberOfExecutors, TestingFixedThreadPool.allExecutors.size()); for (int i = 0; i < expectedTotalNumberOfExecutors - 1; i++) { @@ -309,9 +310,8 @@ public class SimpleConfigurationTest extends AbstractConfigTest { } // return MBeanProxy for 'fixed1' and current transaction - private TestingFixedThreadPoolConfigMXBean startReconfiguringFixed1ThreadPool( - ConfigTransactionJMXClient transaction) - throws InstanceNotFoundException { + private static TestingFixedThreadPoolConfigMXBean startReconfiguringFixed1ThreadPool( + final ConfigTransactionJMXClient transaction) throws InstanceNotFoundException { ObjectName fixed1name = transaction.lookupConfigBean( TestingFixedThreadPoolModuleFactory.NAME, fixed1);