Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / runtimembean / RuntimeBeanRegistratorImplTest.java
index ce3648d1607009aacd5ecc41e2a1f119660d8045..e55e4f76b1814ce73f911514dfee888d8634a633 100644 (file)
@@ -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,17 +7,17 @@
  */
 package org.opendaylight.controller.config.manager.impl.runtimembean;
 
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
-import static org.junit.internal.matchers.StringContains.containsString;
 
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import java.lang.management.ManagementFactory;
 import java.util.Map;
-
 import javax.management.InstanceNotFoundException;
 import javax.management.ObjectName;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -29,29 +29,21 @@ import org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator;
 import org.opendaylight.controller.config.manager.impl.jmx.HierarchicalRuntimeBeanRegistrationImpl;
 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
 
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-public class RuntimeBeanRegistratorImplTest extends
-        AbstractLockedPlatformMBeanServerTest {
-    static final String module1 = "module1";
-    static final String INSTANCE_NAME = "instanceName";
+public class RuntimeBeanRegistratorImplTest extends AbstractLockedPlatformMBeanServerTest {
+    private static final String MODULE1 = "module1";
+    private static final String INSTANCE_NAME = "instanceName";
     String additionalKey = "key";
     String additionalValue = "value";
-    Map<String, String> additionalProperties = ImmutableMap.of(additionalKey,
-            additionalValue);
+    Map<String, String> additionalProperties = ImmutableMap.of(additionalKey, additionalValue);
 
     private BaseJMXRegistrator baseJMXRegistrator;
     private RootRuntimeBeanRegistratorImpl tested;
-    private final ModuleIdentifier moduleIdentifier = new ModuleIdentifier(
-            module1, INSTANCE_NAME);
+    private final ModuleIdentifier moduleIdentifier = new ModuleIdentifier(MODULE1, INSTANCE_NAME);
 
     @Before
     public void setUp() {
-        baseJMXRegistrator = new BaseJMXRegistrator(
-                ManagementFactory.getPlatformMBeanServer());
-        tested = baseJMXRegistrator
-                .createRuntimeBeanRegistrator(moduleIdentifier);
+        baseJMXRegistrator = new BaseJMXRegistrator(ManagementFactory.getPlatformMBeanServer());
+        tested = baseJMXRegistrator.createRuntimeBeanRegistrator(moduleIdentifier);
     }
 
     @After
@@ -60,16 +52,16 @@ public class RuntimeBeanRegistratorImplTest extends
         assertEquals(0, baseJMXRegistrator.getRegisteredObjectNames().size());
     }
 
-    protected void checkExists(ObjectName on) throws Exception {
+    protected void checkExists(final ObjectName on) throws Exception {
         platformMBeanServer.getMBeanInfo(on);
     }
 
-    protected void checkNotExists(ObjectName on) throws Exception {
+    protected void checkNotExists(final ObjectName on) throws Exception {
         try {
             platformMBeanServer.getMBeanInfo(on);
             fail();
-        } catch (InstanceNotFoundException e) {
-
+        } catch (final InstanceNotFoundException e) {
+            // FIXME: should it be empty?
         }
     }
 
@@ -78,13 +70,11 @@ public class RuntimeBeanRegistratorImplTest extends
         createRoot();
     }
 
-    private HierarchicalRuntimeBeanRegistrationImpl createRoot()
-            throws Exception {
-        HierarchicalRuntimeBeanRegistrationImpl rootRegistration = tested
-                .registerRoot(new TestingRuntimeBean());
+    private HierarchicalRuntimeBeanRegistrationImpl createRoot() throws Exception {
+        HierarchicalRuntimeBeanRegistrationImpl rootRegistration = tested.registerRoot(new TestingRuntimeBean());
 
-        ObjectName expectedON1 = ObjectNameUtil.createRuntimeBeanName(module1,
-                INSTANCE_NAME, Maps.<String, String> newHashMap());
+        ObjectName expectedON1 = ObjectNameUtil.createRuntimeBeanName(MODULE1, INSTANCE_NAME,
+                Maps.<String, String>newHashMap());
 
         assertEquals(expectedON1, rootRegistration.getObjectName());
         checkExists(rootRegistration.getObjectName());
@@ -98,14 +88,12 @@ public class RuntimeBeanRegistratorImplTest extends
     }
 
     private HierarchicalRuntimeBeanRegistration createAdditional(
-            HierarchicalRuntimeBeanRegistrationImpl rootRegistration)
-            throws Exception {
+            final HierarchicalRuntimeBeanRegistrationImpl rootRegistration) throws Exception {
 
-        HierarchicalRuntimeBeanRegistrationImpl registration = rootRegistration
-                .register(additionalKey, additionalValue, new TestingRuntimeBean());
+        HierarchicalRuntimeBeanRegistrationImpl registration = rootRegistration.register(additionalKey, additionalValue,
+                new TestingRuntimeBean());
 
-        ObjectName expectedON1 = ObjectNameUtil.createRuntimeBeanName(module1,
-                INSTANCE_NAME, additionalProperties);
+        ObjectName expectedON1 = ObjectNameUtil.createRuntimeBeanName(MODULE1, INSTANCE_NAME, additionalProperties);
 
         assertEquals(expectedON1, registration.getObjectName());
         checkExists(registration.getObjectName());
@@ -140,13 +128,10 @@ public class RuntimeBeanRegistratorImplTest extends
         try {
             createRoot();
             fail();
-        } catch (IllegalStateException e) {
-            assertThat(e.getMessage(), containsString(rootRegistration
-                    .getObjectName().toString()));
-            assertThat(e.getMessage(),
-                    containsString("Could not register runtime bean"));
-            assertThat(e.getMessage(),
-                    containsString(moduleIdentifier.toString()));
+        } catch (final IllegalStateException e) {
+            assertThat(e.getMessage(), containsString(rootRegistration.getObjectName().toString()));
+            assertThat(e.getMessage(), containsString("Could not register runtime bean"));
+            assertThat(e.getMessage(), containsString(moduleIdentifier.toString()));
         }
     }
 
@@ -156,5 +141,4 @@ public class RuntimeBeanRegistratorImplTest extends
         platformMBeanServer.unregisterMBean(rootRegistration.getObjectName());
         rootRegistration.close();
     }
-
 }