X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-api%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fapi%2Fjmx%2FObjectNameUtilTest.java;h=7498561eb2d6c8bc6a5ec2ca7be7deff84a090cf;hb=c65916d075142dd937cb67e5128a87c05616b834;hp=d3d8469dfba7b0409a0c7738be2b43ca76f4a57b;hpb=cb9d74fc36ddcbca1b7fb62941396db1eb3c42c1;p=controller.git diff --git a/opendaylight/config/config-api/src/test/java/org/opendaylight/controller/config/api/jmx/ObjectNameUtilTest.java b/opendaylight/config/config-api/src/test/java/org/opendaylight/controller/config/api/jmx/ObjectNameUtilTest.java index d3d8469dfb..7498561eb2 100644 --- a/opendaylight/config/config-api/src/test/java/org/opendaylight/controller/config/api/jmx/ObjectNameUtilTest.java +++ b/opendaylight/config/config-api/src/test/java/org/opendaylight/controller/config/api/jmx/ObjectNameUtilTest.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,16 +7,16 @@ */ package org.opendaylight.controller.config.api.jmx; -import static junit.framework.Assert.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import com.google.common.base.Throwables; import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import javax.management.ObjectName; -import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.ModuleIdentifier; @@ -45,7 +45,8 @@ public class ObjectNameUtilTest { assertEquals(serviceQName, ObjectNameUtil.getServiceQName(serviceReferenceON)); assertEquals(refName, ObjectNameUtil.getReferenceName(serviceReferenceON)); assertEquals(transaction, ObjectNameUtil.getTransactionName(serviceReferenceON)); - assertEquals(ObjectNameUtil.createReadOnlyServiceON(serviceQName, refName), ObjectNameUtil.withoutTransactionName(serviceReferenceON)); + assertEquals(ObjectNameUtil.createReadOnlyServiceON(serviceQName, refName), + ObjectNameUtil.withoutTransactionName(serviceReferenceON)); serviceReferenceON = ObjectNameUtil.createReadOnlyServiceON(serviceQName, refName); assertFalse(serviceReferenceON.isPattern()); @@ -82,7 +83,7 @@ public class ObjectNameUtilTest { assertPattern(on, pattern); } - private void assertPattern(ObjectName test, ObjectName pattern) { + private void assertPattern(final ObjectName test, final ObjectName pattern) { assertTrue(pattern.isPattern()); assertTrue(pattern.apply(test)); } @@ -124,39 +125,39 @@ public class ObjectNameUtilTest { @Test public void testChecks() throws Exception { - final ObjectName on = ObjectNameUtil.createON("customDomain", ObjectNameUtil.TYPE_KEY, ObjectNameUtil.TYPE_MODULE); - - assertFailure(new Runnable() { - @Override - public void run() { - ObjectNameUtil.checkTypeOneOf(on, ObjectNameUtil.TYPE_RUNTIME_BEAN, ObjectNameUtil.TYPE_CONFIG_TRANSACTION); - } - }, IllegalArgumentException.class); - - assertFailure(new Runnable() { - @Override - public void run() { - ObjectNameUtil.checkType(on, ObjectNameUtil.TYPE_RUNTIME_BEAN); - } - }, IllegalArgumentException.class); - - assertFailure(new Runnable() { - @Override - public void run() { - ObjectNameUtil.checkDomain(on); - } - }, IllegalArgumentException.class); + final ObjectName on = ObjectNameUtil.createON("customDomain", ObjectNameUtil.TYPE_KEY, + ObjectNameUtil.TYPE_MODULE); + + assertFailure(() -> ObjectNameUtil.checkTypeOneOf(on, ObjectNameUtil.TYPE_RUNTIME_BEAN, + ObjectNameUtil.TYPE_CONFIG_TRANSACTION), IllegalArgumentException.class); + + assertFailure(() -> ObjectNameUtil.checkType(on, ObjectNameUtil.TYPE_RUNTIME_BEAN), + IllegalArgumentException.class); + + assertFailure(() -> ObjectNameUtil.checkDomain(on), IllegalArgumentException.class); } - private void assertFailure(Runnable test, Class ex) { + @SuppressWarnings("IllegalCatch") + private void assertFailure(final Runnable test, final Class ex) { try { test.run(); - } catch(Exception e) { - Assert.assertTrue("Failed with wrong exception: " + Throwables.getStackTraceAsString(e), + } catch (final Exception e) { + assertTrue("Failed with wrong exception: " + Throwables.getStackTraceAsString(e), e.getClass().isAssignableFrom(ex)); return; } fail(test + " should have failed on " + ex); } + + @Test(expected = IllegalArgumentException.class) + public void testCreateON() throws Exception { + ObjectNameUtil.createON(">}+!#"); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateON2() throws Exception { + Map map = new HashMap<>(); + ObjectNameUtil.createON(">}+!#", map); + } }