X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FModuleFactoryBundleTrackerTest.java;h=7f6253ea46b0deda09af34570ca81f4a17348a85;hp=fe4775533055e02cdf5eab581baf2ea3f2158f85;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hpb=d70f418d19fa09b1efc8fa4ce4ed35f0cf59b73b diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java index fe47755330..7f6253ea46 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014, 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.config.manager.impl.osgi; import static org.junit.Assert.assertEquals; @@ -18,8 +26,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.opendaylight.controller.config.api.DependencyResolver; import org.opendaylight.controller.config.api.DependencyResolverFactory; import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; @@ -43,12 +49,8 @@ public class ModuleFactoryBundleTrackerTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - return getClass().getClassLoader().loadClass((String) invocation.getArguments()[0]); - } - }).when(bundle).loadClass(anyString()); + doAnswer(invocation -> getClass().getClassLoader().loadClass((String) invocation.getArguments()[0])) + .when(bundle).loadClass(anyString()); doReturn("mockBundle").when(bundle).toString(); doReturn(context).when(bundle).getBundleContext(); doReturn(reg).when(context).registerService(anyString(), anyObject(), any(Dictionary.class)); @@ -61,10 +63,11 @@ public class ModuleFactoryBundleTrackerTest { } @Test + @SuppressWarnings("IllegalCatch") public void testRegisterFactoryInstantiateEx() throws Exception { try { ModuleFactoryBundleTracker.registerFactory(WrongConstructorTestingFactory.class.getName(), bundle); - } catch (Exception e) { + } catch (final Exception e) { verifyZeroInteractions(context); assertNotNull(e.getCause()); assertEquals(InstantiationException.class, e.getCause().getClass()); @@ -75,10 +78,11 @@ public class ModuleFactoryBundleTrackerTest { } @Test + @SuppressWarnings("IllegalCatch") public void testRegisterFactoryInstantiateExAccess() throws Exception { try { ModuleFactoryBundleTracker.registerFactory(NoAccessConstructorTestingFactory.class.getName(), bundle); - } catch (Exception e) { + } catch (final Exception e) { verifyZeroInteractions(context); assertNotNull(e.getCause()); assertEquals(IllegalAccessException.class, e.getCause().getClass()); @@ -89,10 +93,11 @@ public class ModuleFactoryBundleTrackerTest { } @Test + @SuppressWarnings("IllegalCatch") public void testRegisterFactoryNotExtending() throws Exception { try { ModuleFactoryBundleTracker.registerFactory(NotExtendingTestingFactory.class.getName(), bundle); - } catch (Exception e) { + } catch (final Exception e) { verifyZeroInteractions(context); return; } @@ -101,10 +106,11 @@ public class ModuleFactoryBundleTrackerTest { } @Test + @SuppressWarnings("IllegalCatch") public void testRegisterFactoryNotExisting() throws Exception { try { ModuleFactoryBundleTracker.registerFactory("Unknown class", bundle); - } catch (Exception e) { + } catch (final Exception e) { verifyZeroInteractions(context); assertNotNull(e.getCause()); assertEquals(ClassNotFoundException.class, e.getCause().getClass()); @@ -126,12 +132,13 @@ public class ModuleFactoryBundleTrackerTest { } @Test + @SuppressWarnings("IllegalCatch") public void testAddingBundleError() throws Exception { final ModuleFactoryBundleTracker tracker = new ModuleFactoryBundleTracker(blankTxTracker); doReturn(getClass().getResource("/module-factories/module-factory-fail")).when(bundle).getEntry(anyString()); try { tracker.addingBundle(bundle, mock(BundleEvent.class)); - } catch (Exception e) { + } catch (final Exception e) { verifyZeroInteractions(context); return; } @@ -144,9 +151,10 @@ public class ModuleFactoryBundleTrackerTest { } } - static class NotExtendingTestingFactory {} + static class NotExtendingTestingFactory { + } - static class NoAccessConstructorTestingFactory extends TestingFactory { + static final class NoAccessConstructorTestingFactory extends TestingFactory { private NoAccessConstructorTestingFactory() { } } @@ -165,17 +173,20 @@ public class ModuleFactoryBundleTrackerTest { } @Override - public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, final BundleContext bundleContext) { + public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, + final BundleContext bundleContext) { throw new UnsupportedOperationException(); } @Override - public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception { + public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, + final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception { throw new UnsupportedOperationException(); } @Override - public boolean isModuleImplementingServiceInterface(final Class serviceInterface) { + public boolean isModuleImplementingServiceInterface( + final Class serviceInterface) { throw new UnsupportedOperationException(); } @@ -185,7 +196,8 @@ public class ModuleFactoryBundleTrackerTest { } @Override - public Set getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) { + public Set getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, + final BundleContext bundleContext) { throw new UnsupportedOperationException(); } }