From 37493df2ce7ec4bd9a2e1117dcc594c54731e388 Mon Sep 17 00:00:00 2001 From: Marian Adamjak Date: Fri, 24 Oct 2014 14:49:12 +0200 Subject: [PATCH] BUG 2245 - Fix Unnecessary Local Before Return Change-Id: I6fc4762d8af5cced96e82529cf23d75bb017dffa Signed-off-by: Marian Adamjak --- .../impl/connection/SwitchConnectionProviderImpl.java | 8 +++++--- .../connection/SwitchConnectionProviderImpl02Test.java | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index 75f698c4..002343d7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -97,9 +97,11 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { @Override public ListenableFuture shutdown() { LOGGER.debug("Shutdown summoned"); - //TODO: provide exception in case of: not started, not configured (already stopped) - ListenableFuture result = serverFacade.shutdown(); - return result; + if(serverFacade == null){ + LOGGER.debug("Can not shutdown - not configured or started"); + throw new IllegalStateException("SwitchConnectionProvider is not started or not configured."); + } + return serverFacade.shutdown(); } @Override diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl02Test.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl02Test.java index e0fecc27..c388c682 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl02Test.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl02Test.java @@ -112,6 +112,14 @@ public class SwitchConnectionProviderImpl02Test { Assert.assertNotNull("Wrong -- getServerFacade return null",serverFacade); } + /** + * Test shutdown on unconfigured provider + */ + @Test(expected = IllegalStateException.class) + public void testShutdownUnconfigured(){ + startUp(TransportProtocol.TCP); + provider.shutdown(); + } /** * Test unregister by wrong key */ -- 2.36.6