X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Ffactoriesresolver%2FHardcodedModuleFactoriesResolver.java;h=b6cc61e1e3175c289ea607ee4f405876819ef045;hb=2b78ca93f44c372fd72927db6cbd65f5d8387b49;hp=dd6588f3f63cb7c0f06589f1890cb68c3f94b619;hpb=0c931b8d1fa153991b10705a4358fe39f93181cd;p=controller.git diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HardcodedModuleFactoriesResolver.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HardcodedModuleFactoriesResolver.java index dd6588f3f6..b6cc61e1e3 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HardcodedModuleFactoriesResolver.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HardcodedModuleFactoriesResolver.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, @@ -7,72 +7,35 @@ */ package org.opendaylight.controller.config.manager.impl.factoriesresolver; -import org.mockito.Matchers; -import org.mockito.Mockito; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; import org.opendaylight.controller.config.spi.ModuleFactory; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import java.io.Closeable; -import java.util.Arrays; -import java.util.Dictionary; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.util.AbstractMap; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; public class HardcodedModuleFactoriesResolver implements ModuleFactoriesResolver { - private Map> factories; + private final Map> factories; - public HardcodedModuleFactoriesResolver(BundleContext bundleContext, ModuleFactory... list) { - List factoryList = Arrays.asList(list); - this.factories = new HashMap<>(factoryList.size()); + public HardcodedModuleFactoriesResolver(final BundleContext bundleContext, final ModuleFactory... list) { + this.factories = new HashMap<>(list.length); for (ModuleFactory moduleFactory : list) { - StringBuffer errors = new StringBuffer(); String moduleName = moduleFactory.getImplementationName(); if (moduleName == null || moduleName.isEmpty()) { - throw new IllegalStateException( - "Invalid implementation name for " + moduleFactory); + throw new IllegalStateException("Invalid implementation name for " + moduleFactory); } - String error = null; Map.Entry conflicting = factories.get(moduleName); - if (conflicting != null) { - error = String - .format("Module name is not unique. Found two conflicting factories with same name '%s': " + - "\n\t%s\n\t%s\n", moduleName, conflicting.getKey(), moduleFactory); - - } - - if (error == null) { - factories.put(moduleName, new AbstractMap.SimpleEntry<>(moduleFactory, - bundleContext)); + if (conflicting == null) { + factories.put(moduleName, new AbstractMap.SimpleEntry<>(moduleFactory, bundleContext)); } else { - errors.append(error); - } - if (errors.length() > 0) { - throw new IllegalArgumentException(errors.toString()); + throw new IllegalArgumentException(String.format( + "Module name is not unique. Found two conflicting factories with same name '%s':\n\t%s\n\t%s\n", + moduleName, conflicting.getKey(), moduleFactory)); } } } - private static BundleContext mockBundleContext() { - BundleContext bundleContext = Mockito.mock(BundleContext.class); - ServiceRegistration serviceRegistration = mock(ServiceRegistration.class); - doNothing().when(serviceRegistration).unregister(); - doReturn(serviceRegistration).when(bundleContext).registerService( - Matchers.any(String[].class), any(Closeable.class), - any(Dictionary.class)); - return bundleContext; - } - @Override public Map> getAllFactories() { return factories; } - }