X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=test%2Fnet%2Fjaekl%2Fcfb%2FCFBTest.java;h=1e70fb28ae81dd11b3d5da7eefe9d2a0cdfa2969;hb=a62d41ddf11fd3769f6894b4385314f536360a89;hp=08d9c393f626e431214536a7001933d6adce3301;hpb=e6448f6cf67e5a5409f24b531c2443b3bed53b52;p=cfb.git diff --git a/test/net/jaekl/cfb/CFBTest.java b/test/net/jaekl/cfb/CFBTest.java index 08d9c39..1e70fb2 100644 --- a/test/net/jaekl/cfb/CFBTest.java +++ b/test/net/jaekl/cfb/CFBTest.java @@ -1,6 +1,7 @@ package net.jaekl.cfb; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -107,6 +108,53 @@ public class CFBTest { m_cfb = new CFBMock(Locale.getDefault(), m_driver); } + @Test + public void testParseArgs_noParams() throws IOException + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + String[] args = {}; + + boolean result = m_cfb.parseArgs(pw, args); + pw.close(); + sw.close(); + + assertFalse(result); + assertEquals("[must.specify.fbp.file]\n[invoke.with.help.for.help]\n", sw.toString()); + } + + @Test + public void testParseArgs_dropTables() throws IOException + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + String[] args = { "--drop-tables" }; + + boolean result = m_cfb.parseArgs(pw, args); + pw.close(); + sw.close(); + + assertTrue(result); + assertEquals("", sw.toString()); + } + + @Test + public void testParseArgs_invalidParam() throws IOException + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + String[] args = {"--xyzzyaoeuidhtnsl"}; + + boolean result = m_cfb.parseArgs(pw, args); + pw.close(); + sw.close(); + String actual = sw.toString(); + + assertFalse(result); + assertTrue(actual.contains("usage")); + assertTrue(actual.contains("--help")); + } + @Test public void testStoreAndReport_noPrior() throws IOException, SQLException, SAXException, TypeMismatchException { @@ -171,33 +219,39 @@ public class CFBTest { null, null, "[cannot.load.fbmsg.file][null]\n[findbugs.home.is.not.set][FINDBUGS_HOME]\n" } }; - EnvMock envMock = EnvMock.mock_putInstance(); - - for (String[] datum : data) - { - String fbHome = datum[0]; - String filename = datum[1]; - String expected = datum[2]; + + try { + EnvMock envMock = EnvMock.mock_putInstance(); - try ( - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - ) + for (String[] datum : data) { - envMock.mock_putEnv(CFB.FINDBUGS_HOME, fbHome); - FBMsgFileNotFoundException exc = new FBMsgFileNotFoundException(filename); - m_cfb.reportException(pw, exc); + String fbHome = datum[0]; + String filename = datum[1]; + String expected = datum[2]; - pw.close(); - sw.close(); - - String actual = sw.toString(); - boolean pass = actual.endsWith(expected); - if (!pass) { - System.out.println("Expected:\n" + expected + "\nActual:\n" + actual); + try ( + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + ) + { + envMock.mock_putEnv(CFB.FINDBUGS_HOME, fbHome); + FBMsgFileNotFoundException exc = new FBMsgFileNotFoundException(filename); + m_cfb.reportException(pw, exc); + + pw.close(); + sw.close(); + + String actual = sw.toString(); + boolean pass = actual.endsWith(expected); + if (!pass) { + System.out.println("Expected:\n" + expected + "\nActual:\n" + actual); + } + assertTrue(pass); } - assertTrue(pass); } } + finally { + EnvMock.mock_resetInstance(); + } } }