From b9a61f16cdffcfffb38f4bc34828b2ee2ebe6589 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Thu, 9 Nov 2017 16:28:42 +0100 Subject: Add static modifier + fix warnings --- .../standalone/StandaloneContainerActivator.java | 8 +++--- .../StandaloneContainerActivatorTest.java | 31 +++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java b/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java index 79947b5a347..baf0b41b270 100644 --- a/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java +++ b/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java @@ -42,13 +42,13 @@ public class StandaloneContainerActivator implements BundleActivator { } } - void registerChannels(BundleContext bundleContext, int listenPort, ServerSocketChannel boundChannel) { + static void registerChannels(BundleContext bundleContext, int listenPort, ServerSocketChannel boundChannel) { Hashtable properties = new Hashtable<>(); properties.put("port", listenPort); bundleContext.registerService(ServerSocketChannel.class, boundChannel, properties); } - ServerSocketChannel bindChannel(ConnectorConfig channelInfo) throws IOException { + static ServerSocketChannel bindChannel(ConnectorConfig channelInfo) throws IOException { ServerSocketChannel serverChannel = ServerSocketChannel.open(); InetSocketAddress bindAddress = new InetSocketAddress(channelInfo.listenPort()); serverChannel.socket().bind(bindAddress, channelInfo.acceptQueueSize()); @@ -58,7 +58,7 @@ public class StandaloneContainerActivator implements BundleActivator { @Override public void stop(BundleContext bundleContext) throws Exception { } - Container getContainer(Module... modules) { + static Container getContainer(Module... modules) { Module activatorModule = new ActivatorModule(); List allModules = new ArrayList<>(); allModules.addAll(Arrays.asList(modules)); @@ -68,7 +68,7 @@ public class StandaloneContainerActivator implements BundleActivator { return app.container(); } - List getConnectorConfigs(Container container) { + static List getConnectorConfigs(Container container) { Http http = container.getHttp(); return (http == null) ? diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java index 48c882c78db..8d413ade0f0 100644 --- a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java +++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.standalone; -import com.google.inject.Binder; import com.google.inject.Module; import com.yahoo.io.IOUtils; import com.yahoo.jdisc.http.ConnectorConfig; @@ -18,6 +17,7 @@ import java.nio.file.Path; import java.util.List; import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.collection.IsEmptyCollection.empty; @@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat; */ public class StandaloneContainerActivatorTest { - private String getJdiscXml(String contents) throws ParserConfigurationException, IOException, SAXException { + private static String getJdiscXml(String contents) throws ParserConfigurationException, IOException, SAXException { return "\n" + "\n" + " \n" + @@ -38,7 +38,7 @@ public class StandaloneContainerActivatorTest { ""; } - private void writeApplicationPackage(String servicesXml, Path tmpDir) throws IOException { + private static void writeApplicationPackage(String servicesXml, Path tmpDir) throws IOException { FileWriter fw = new FileWriter(tmpDir.resolve("services.xml").toFile(), false); fw.write(servicesXml); fw.close(); @@ -50,16 +50,16 @@ public class StandaloneContainerActivatorTest { try { writeApplicationPackage(getJdiscXml(""), applicationDir); StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = activator.getContainer(newAppDirBinding(applicationDir)); + Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); List ports = getPorts(activator, container); - assertThat(ports, is(asList(Defaults.getDefaults().vespaWebServicePort()))); + assertThat(ports, is(singletonList(Defaults.getDefaults().vespaWebServicePort()))); } finally { IOUtils.recursiveDeleteDir(applicationDir.toFile()); } } - private List getPorts(StandaloneContainerActivator activator, Container container) { - return activator.getConnectorConfigs(container).stream(). + private static List getPorts(StandaloneContainerActivator activator, Container container) { + return StandaloneContainerActivator.getConnectorConfigs(container).stream(). map(ConnectorConfig::listenPort). collect(toList()); } @@ -70,7 +70,7 @@ public class StandaloneContainerActivatorTest { try { writeApplicationPackage(getJdiscXml(""), applicationDir); StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = activator.getContainer(newAppDirBinding(applicationDir)); + Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); List ports = getPorts(activator, container); assertThat(ports, empty()); } finally { @@ -90,7 +90,7 @@ public class StandaloneContainerActivatorTest { "\n"; writeApplicationPackage(getJdiscXml(contents), applicationDir); StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = activator.getContainer(newAppDirBinding(applicationDir)); + Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); List ports = getPorts(activator, container); assertThat(ports, is(asList(123, 456, 789))); } finally { @@ -98,15 +98,10 @@ public class StandaloneContainerActivatorTest { } } - private Module newAppDirBinding(final Path applicationDir) { - return new Module() { - @Override - public void configure(Binder binder) { - binder.bind(Path.class) - .annotatedWith(StandaloneContainerApplication.applicationPathName()) - .toInstance(applicationDir); - } - }; + private static Module newAppDirBinding(final Path applicationDir) { + return binder -> binder.bind(Path.class) + .annotatedWith(StandaloneContainerApplication.applicationPathName()) + .toInstance(applicationDir); } } -- cgit v1.2.3