Address some edge cases related to bootstrapping a fresh system.
[cfb.git] / test / net / jaekl / cfb / CFBTest.java
index 6d446676e0e32d1243830f7c537fc1f44a0fc673..1e70fb28ae81dd11b3d5da7eefe9d2a0cdfa2969 100644 (file)
@@ -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 
        {