From 4957d89b501b711b0afce8df54860d244a62b63b Mon Sep 17 00:00:00 2001 From: Jono Date: Thu, 20 Feb 2020 21:27:10 +1300 Subject: [PATCH] 1. Reinstate missing imports to ZooKeeperMain. 2. Add unit tests for CommandFactory. 3. Remove redundant import from CommandFactory. --- .../org/apache/zookeeper/ZooKeeperMain.java | 3 +++ .../apache/zookeeper/cli/CommandFactory.java | 2 -- .../zookeeper/cli/CommandFactoryTest.java | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 zookeeper-server/src/test/java/org/apache/zookeeper/cli/CommandFactoryTest.java diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java index d7f4b3ccde5..008adc835ef 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java @@ -40,6 +40,9 @@ import org.apache.zookeeper.admin.ZooKeeperAdmin; import org.apache.zookeeper.cli.CliCommand; import org.apache.zookeeper.cli.CommandFactory; +import org.apache.zookeeper.cli.CommandNotFoundException; +import org.apache.zookeeper.cli.CliException; +import org.apache.zookeeper.cli.MalformedCommandException; import org.apache.zookeeper.client.ZKClientConfig; import org.apache.zookeeper.server.ExitCode; import org.apache.zookeeper.util.ServiceUtils; diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/CommandFactory.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/CommandFactory.java index 3eb51a482f6..9ecca139b40 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/CommandFactory.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/CommandFactory.java @@ -1,7 +1,5 @@ package org.apache.zookeeper.cli; -import org.apache.zookeeper.server.admin.Command; - import java.util.function.Supplier; /** diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/cli/CommandFactoryTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/cli/CommandFactoryTest.java new file mode 100644 index 00000000000..f86e020bf0b --- /dev/null +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/cli/CommandFactoryTest.java @@ -0,0 +1,20 @@ +package org.apache.zookeeper.cli; + +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +/** + * Unit test for {@link CommandFactory}. + */ +public class CommandFactoryTest { + + /** + * Verify that the {@code CommandFactory} can create a command instance. + */ + @Test + public void testCommandCreation() { + CliCommand cliCommand = + CommandFactory.getInstance(CommandFactory.Command.CREATE); + assertTrue(cliCommand instanceof CreateCommand); + } +}