From b4ba61e92e6d7078e455ae109a594c093a9ee114 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Tue, 9 Dec 2014 22:19:15 +0100 Subject: [PATCH] added first test class --- java/.classpath | 1 + .../src/to/mmo/cmdlineoptions/test/Tests.java | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 java/src/to/mmo/cmdlineoptions/test/Tests.java diff --git a/java/.classpath b/java/.classpath index fb50116..3e0fb27 100644 --- a/java/.classpath +++ b/java/.classpath @@ -2,5 +2,6 @@ + diff --git a/java/src/to/mmo/cmdlineoptions/test/Tests.java b/java/src/to/mmo/cmdlineoptions/test/Tests.java new file mode 100644 index 0000000..a807a5e --- /dev/null +++ b/java/src/to/mmo/cmdlineoptions/test/Tests.java @@ -0,0 +1,84 @@ +package to.mmo.cmdlineoptions.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import to.mmo.cmdlineoptions.CmdOptions; + +public class Tests { + + @Before + public void setupCmdOptions() { + CmdOptions.i().createOption("test").addCommand("t") + .addLongCommand("test").setParameterCount(0, 1); + CmdOptions.i().createOption("test2").addCommand("f"); + CmdOptions.i().createOption("complex").addCommand("c") + .addLongCommand("complex").addDefaultParameter("wtf") + .addPossibleParameter("wtf").addPossibleParameter("wth"); + } + + @Test + public void testSingle() { + CmdOptions.i().setShowOptions(false); + String argstr = "-t"; + String[] args = argstr.split(" "); + CmdOptions.i().parse(args); + + assertTrue(CmdOptions.i().isSet("test")); + // assertEquals("test", CmdOptions.i().get("test")[0]); + } + + @Test + public void testSingle2() { + CmdOptions.i().setShowOptions(false); + String argstr = "-t test"; + String[] args = argstr.split(" "); + CmdOptions.i().parse(args); + + assertTrue(CmdOptions.i().isSet("test")); + assertEquals("test", CmdOptions.i().get("test")[0]); + } + + @Test + public void testMore() { + CmdOptions.i().setSwitchCombination(true); + CmdOptions.i().setShowOptions(false); + String argstr = "-tf"; + String[] args = argstr.split(" "); + CmdOptions.i().parse(args); + + assertTrue(CmdOptions.i().isSet("test")); + assertTrue(CmdOptions.i().isSet("test2")); + } + + @Test + public void testMoreSwitches() { + CmdOptions.i().setSwitchCombination(true); + CmdOptions.i().setShowOptions(true); + CmdOptions.i().setDontQuitOnError(true); + String argstr = "-tsf"; + String[] args = argstr.split(" "); + int e = CmdOptions.i().parse(args); + + assertEquals(1, e); + } + + @Test + public void testComplex() { + CmdOptions.i().setSwitchCombination(true); + CmdOptions.i().setShowOptions(true); + String argstr = "-tf -c wth"; + String[] args = argstr.split(" "); + CmdOptions.i().parse(args); + + } + + @After + public void reset() { + CmdOptions.i().resetValues(); + } +}