[Japi-cvs] SF.net SVN: japi:[869] libs/argparser/trunk/src/tst/test/net/sf/japi/io/ args
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2009-02-15 12:12:37
|
Revision: 869
http://japi.svn.sourceforge.net/japi/?rev=869&view=rev
Author: christianhujer
Date: 2009-02-15 11:58:33 +0000 (Sun, 15 Feb 2009)
Log Message:
-----------
Improved Unit tests, e.g. add messages, bring expected and actual in right order, use assertEquals.
Modified Paths:
--------------
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/BasicCommandTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MethodOptionComparatorTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/TerminalExceptionTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractConverterTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractPrimitiveConverterTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConstructorConverterTest.java
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/BasicCommandTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/BasicCommandTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/BasicCommandTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -38,32 +38,23 @@
@Test
public void testBasicCommand() throws Exception {
final BasicCommand basicCommand = new CommandDummy();
- Assert.assertEquals(0, basicCommand.run(new ArrayList<String>()));
+ Assert.assertEquals("Command dummy must run successful.", 0, basicCommand.run(new ArrayList<String>()));
}
/**
- * Tests that {@link BasicCommand#setExiting(Boolean)} works.
+ * Tests that {@link BasicCommand#setExiting(Boolean)} and {@link BasicCommand#isExiting()} work.
* @throws Exception (unexpected)
*/
@Test
- public void testSetExiting() throws Exception {
+ public void testExiting() throws Exception {
final BasicCommand basicCommand = new CommandDummy();
basicCommand.setExiting(false);
- Assert.assertFalse(basicCommand.isExiting());
+ Assert.assertFalse("Exiting value must be stored.", basicCommand.isExiting());
basicCommand.setExiting(true);
- Assert.assertTrue(basicCommand.isExiting());
+ Assert.assertTrue("Exiting value must be stored.", basicCommand.isExiting());
}
/**
- * Tests that {@link BasicCommand#isExiting()} works.
- * @throws Exception (unexpected)
- */
- @Test
- public void testIsExiting() throws Exception {
- testSetExiting();
- }
-
- /**
* Tests that {@link BasicCommand#help()} works.
* @throws Exception (unexpected)
*/
@@ -81,7 +72,7 @@
public void testGetBundle() throws Exception {
final BasicCommand basicCommand = new CommandDummy();
final ResourceBundle bundle = basicCommand.getBundle();
- Assert.assertNotNull(bundle);
+ Assert.assertNotNull("CommandDummy must have a bundle.", bundle);
}
/**
@@ -95,61 +86,38 @@
public void testGetString() {
final RBMockCommand mock = new RBMockCommand();
mock.setReturnOwnBundle(false);
- Assert.assertEquals("String1FromDefaultBundle", mock.getString("testGetString1"));
- Assert.assertEquals("String2FromDefaultBundle", mock.getString("testGetString2"));
+ Assert.assertEquals("if setReturnOwnBundle(false), getString() must retrieve from default bundle.", "String1FromDefaultBundle", mock.getString("testGetString1"));
+ Assert.assertEquals("if setReturnOwnBundle(false), getString() must retrieve from default bundle.", "String2FromDefaultBundle", mock.getString("testGetString2"));
mock.setReturnOwnBundle(true);
- Assert.assertEquals("String1FromMyBundle", mock.getString("testGetString1"));
- Assert.assertEquals("String2FromDefaultBundle", mock.getString("testGetString2"));
+ Assert.assertEquals("if setReturnOwnBundle(true), getString() must retrieve from own bundle.", "String1FromMyBundle", mock.getString("testGetString1"));
+ Assert.assertEquals("if setReturnOwnBundle(true), getString() must retrieve from own bundle.", "String2FromDefaultBundle", mock.getString("testGetString2"));
}
/**
* Tests that {@link BasicCommand#getHelpHeader()} returns the value from the correct bundle.
+ * Also, the help header must always be terminated with '\n', which will be auto-appended by {@link BasicCommand#getHelpHeader()}.
+ * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1812417&group_id=149894&atid=776737">[ 1812417 ] auto-add newline to help header and footer</a>
*/
@Test
public void testGetHelpHeader() {
final RBMockCommand mock = new RBMockCommand();
mock.setReturnOwnBundle(false);
- Assert.assertEquals("HelpHeaderFromDefaultBundle", mock.getString("helpHeader"));
+ Assert.assertEquals("if setReturnOwnBundle(false), getHelpHeader() must retrieve from default bundle and end with newline.", "HelpHeaderFromDefaultBundle\n", mock.getHelpHeader());
mock.setReturnOwnBundle(true);
- Assert.assertEquals("HelpHeaderFromMyBundle", mock.getString("helpHeader"));
+ Assert.assertEquals("if setReturnOwnBundle(true), getHelpHeader() must retrieve from own bundle and end with newline.", "HelpHeaderFromMyBundle\n", mock.getHelpHeader());
}
/**
- * Tests that {@link BasicCommand#getHelpHeader()} returns either the empty String or a String ending on "\n".
+ * Tests that {@link BasicCommand#getHelpFooter()} returns either the empty String or a String ending on "\n".
* @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1812417&group_id=149894&atid=776737">[ 1812417 ] auto-add newline to help header and footer</a>
*/
@Test
- public void testGetHelpHeaderNewline() {
- final RBMockCommand mock = new RBMockCommand();
- mock.setReturnOwnBundle(false);
- Assert.assertEquals("HelpHeaderFromDefaultBundle\n", mock.getHelpHeader());
- mock.setReturnOwnBundle(true);
- Assert.assertEquals("HelpHeaderFromMyBundle\n", mock.getHelpHeader());
- }
-
- /**
- * Tests that {@link BasicCommand#getHelpFooter()} returns the value from the correct bundle.
- */
- @Test
public void testGetHelpFooter() {
final RBMockCommand mock = new RBMockCommand();
mock.setReturnOwnBundle(false);
- Assert.assertEquals("HelpFooterFromDefaultBundle", mock.getString("helpFooter"));
+ Assert.assertEquals("if setReturnOwnBundle(false), getHelpFooter() must retrieve from default bundle and end with newline.", "HelpFooterFromDefaultBundle\n", mock.getHelpFooter());
mock.setReturnOwnBundle(true);
- Assert.assertEquals("HelpFooterFromMyBundle", mock.getString("helpFooter"));
+ Assert.assertEquals("if setReturnOwnBundle(true), getHelpFooter() must retrieve from own bundle and end with newline.", "HelpFooterFromMyBundle\n", mock.getHelpFooter());
}
- /**
- * Tests that {@link BasicCommand#getHelpFooter()} returns either the empty String or a String ending on "\n".
- * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1812417&group_id=149894&atid=776737">[ 1812417 ] auto-add newline to help header and footer</a>
- */
- @Test
- public void testGetHelpFooterNewline() {
- final RBMockCommand mock = new RBMockCommand();
- mock.setReturnOwnBundle(false);
- Assert.assertEquals("HelpFooterFromDefaultBundle\n", mock.getHelpFooter());
- mock.setReturnOwnBundle(true);
- Assert.assertEquals("HelpFooterFromMyBundle\n", mock.getHelpFooter());
- }
-
} // class BasicCommandTest
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MethodOptionComparatorTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MethodOptionComparatorTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MethodOptionComparatorTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -62,7 +62,7 @@
final Class<MockCommand> cmdClass = MockCommand.class;
final Method mC1 = cmdClass.getMethod("c1");
final Method mC2 = cmdClass.getMethod("c2");
- Assert.assertTrue("-c and -C must not be the same.", comparator.compare(mC1, mC2) != 0);
+ Assert.assertNotSame("-c and -C must not be the same.", 0, comparator.compare(mC1, mC2));
}
/** Mock Command with methods that should be properly sorted.
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/MissingArgumentExceptionTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -37,7 +37,7 @@
@Test
public void testMissingArgumentException() throws Exception {
final MissingArgumentException exception = new MissingArgumentException("foo");
- Assert.assertEquals(exception.getOption(), "foo");
+ Assert.assertEquals("foo", exception.getOption());
}
/**
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/TerminalExceptionTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/TerminalExceptionTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/TerminalExceptionTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -37,7 +37,7 @@
@Test
public void testTerminalException() throws Exception {
final TerminalException exception = new TerminalException();
- Assert.assertEquals(exception.getReturnCode(), 0);
+ Assert.assertEquals("The default return code for TerminalException must be 0 (no error, e.g. for --help).", 0, exception.getReturnCode());
}
/**
@@ -48,7 +48,7 @@
@Test
public void testGetReturnCode() throws Exception {
final TerminalException exception = new TerminalException(1);
- Assert.assertEquals(exception.getReturnCode(), 1);
+ Assert.assertEquals("A specified return code must be stored.", 1, exception.getReturnCode());
}
} // class TerminalExceptionTest
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/UnknownOptionExceptionTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -39,7 +39,7 @@
public void testUnknownOptionException() throws Exception {
final String[] options = { "foo", "bar" };
final UnknownOptionException exception = new UnknownOptionException(options.clone());
- Assert.assertTrue(Arrays.equals(options, exception.getUnknownOptions()));
+ Assert.assertTrue("Options which have been unknown must be stored with the exceptions.", Arrays.equals(options, exception.getUnknownOptions()));
}
/**
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractConverterTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractConverterTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -80,7 +80,7 @@
*/
@Test
public void testGetTargetClass() throws Exception {
- Assert.assertSame(targetClass, converter.getTargetClass());
+ Assert.assertSame("The target class must be stored.", targetClass, converter.getTargetClass());
}
/**
@@ -90,9 +90,9 @@
@Test
public void testGetDescription() throws Exception {
final String description = converter.getDescription();
- Assert.assertNotNull(description);
- Assert.assertTrue(description.length() > 0);
- Assert.assertEquals(description, converter.getDescription(Locale.getDefault()));
+ Assert.assertNotNull("The description must not be null.", description);
+ Assert.assertTrue("The description must not be empty.", description.length() > 0);
+ Assert.assertEquals("The description must be returned in the default locale.", description, converter.getDescription(Locale.getDefault()));
}
/**
@@ -102,9 +102,9 @@
@Test
public void testGetDisplayName() throws Exception {
final String displayName = converter.getDisplayName();
- Assert.assertNotNull(displayName);
- Assert.assertTrue(displayName.length() > 0);
- Assert.assertEquals(displayName, converter.getDisplayName(Locale.getDefault()));
+ Assert.assertNotNull("The display name must not be null.", displayName);
+ Assert.assertTrue("The display name must not be empty.", displayName.length() > 0);
+ Assert.assertEquals("The display name must be returned in the default locale.", displayName, converter.getDisplayName(Locale.getDefault()));
}
/** Returns the converter that's being tested.
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractPrimitiveConverterTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractPrimitiveConverterTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/AbstractPrimitiveConverterTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -95,7 +95,7 @@
*/
@Test
public void testGetTargetClass() throws Exception {
- Assert.assertSame(targetClass, converter.getTargetClass());
+ Assert.assertSame("The target class must be stored.", targetClass, converter.getTargetClass());
}
/**
@@ -105,9 +105,9 @@
@Test
public void testGetDescription() throws Exception {
final String description = converter.getDescription();
- Assert.assertNotNull(description);
- Assert.assertTrue(description.length() > 0);
- Assert.assertEquals(description, converter.getDescription(Locale.getDefault()));
+ Assert.assertNotNull("The description must not be null.", description);
+ Assert.assertTrue("The description must not be empty.", description.length() > 0);
+ Assert.assertEquals("The description must be returned in the default locale.", description, converter.getDescription(Locale.getDefault()));
}
/**
@@ -117,9 +117,9 @@
@Test
public void testGetDisplayName() throws Exception {
final String displayName = converter.getDisplayName();
- Assert.assertNotNull(displayName);
- Assert.assertTrue(displayName.length() > 0);
- Assert.assertEquals(displayName, converter.getDisplayName(Locale.getDefault()));
+ Assert.assertNotNull("The display name must not be null.", displayName);
+ Assert.assertTrue("The display name must not be empty.", displayName.length() > 0);
+ Assert.assertEquals("The display name must be returned in the default locale.", displayName, converter.getDisplayName(Locale.getDefault()));
}
/** Returns the converter that's being tested.
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConstructorConverterTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConstructorConverterTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConstructorConverterTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -37,8 +37,8 @@
@Test
public void testConstructorConverter() throws Exception {
final ConstructorConverter<String> conv = new ConstructorConverter<String>(String.class);
- Assert.assertEquals("foo", conv.convert("foo"));
- Assert.assertEquals("foo", conv.convert(Locale.GERMANY, "foo"));
+ Assert.assertEquals("Correct String must be returned.", "foo", conv.convert("foo"));
+ Assert.assertEquals("Correct String must be returned.", "foo", conv.convert(Locale.GERMANY, "foo"));
}
/** Tests that creating a ConstructorConverter works.
@@ -47,8 +47,8 @@
@Test
public void testConstructorConverter2() throws Exception {
final ConstructorConverter<File> conv = new ConstructorConverter<File>(File.class);
- Assert.assertEquals(new File("foo"), conv.convert("foo"));
- Assert.assertEquals(new File("foo"), conv.convert(Locale.GERMANY, "foo"));
+ Assert.assertEquals("Correct file must be returned.", new File("foo"), conv.convert("foo"));
+ Assert.assertEquals("Correct file muts be returned.", new File("foo"), conv.convert(Locale.GERMANY, "foo"));
}
/** Tests that creating a ConstructorConverter for non-public constructors fails.
@@ -67,12 +67,12 @@
final ConstructorConverter<String> conv1 = new ConstructorConverter<String>(String.class);
final ConstructorConverter<String> conv2 = new ConstructorConverter<String>(String.class);
final ConstructorConverter<File> conv3 = new ConstructorConverter<File>(File.class);
- Assert.assertTrue(conv1.equals(conv2));
- Assert.assertFalse(conv1.equals(new Object()));
+ Assert.assertEquals("Two Converter constructed for the same type must be equal.", conv1, conv2);
+ Assert.assertFalse("A Converter must not be equal to an arbitrary Object.", conv1.equals(new Object()));
//noinspection ObjectEqualsNull
- Assert.assertFalse(conv1.equals(null));
+ Assert.assertFalse("A Converter must not be equal to null.", conv1.equals(null));
//noinspection EqualsBetweenInconvertibleTypes
- Assert.assertFalse(conv1.equals(conv3));
+ Assert.assertFalse("A Converter must not be equal to a Converter for a different type.", conv1.equals(conv3));
}
/** Tests that {@link ConstructorConverter#hashCode()} works.
@@ -82,7 +82,7 @@
public void testHashCode() throws Exception {
final ConstructorConverter<File> conv = new ConstructorConverter<File>(File.class);
final Constructor<File> constructor = File.class.getConstructor(String.class);
- Assert.assertEquals(conv.hashCode(), constructor.hashCode());
+ Assert.assertEquals("The hashCode of a ConstructorConverter must be the hashCode of the constructor used.", conv.hashCode(), constructor.hashCode());
}
/** Tests that {@link ConstructorConverter#getConstructor(Class)} works.
@@ -91,7 +91,7 @@
@Test
public void testGetConstructor() throws Exception {
final Constructor<File> constructor = ConstructorConverter.getConstructor(File.class);
- Assert.assertEquals(File.class.getConstructor(String.class), constructor);
+ Assert.assertEquals("The Constructor returned by a ConstructorConverter must be the correct Constructor.", File.class.getConstructor(String.class), constructor);
}
/** Tests that {@link ConstructorConverter#getConstructor(Class)} throws an Exception for non-public constructors.
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java 2009-02-15 11:58:09 UTC (rev 868)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/converter/ConverterRegistryTest.java 2009-02-15 11:58:33 UTC (rev 869)
@@ -120,7 +120,7 @@
@Test
public void testGetConstructorConverter() throws Exception {
Assert.assertEquals(new ConstructorConverter<String>(String.class), ConverterRegistry.getConstructorConverter(String.class));
- Assert.assertEquals(null, ConverterRegistry.getConstructorConverter(System.class));
+ Assert.assertNull(ConverterRegistry.getConstructorConverter(System.class));
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|