public void testAbstractMainClass() throws Exception { final LoggerStubFactory loggerStubFactory = new LoggerStubFactory(); final Logger logger = loggerStubFactory.getLogger(); final String myUsage = "do some stuff"; final MyMainClass mainClass = new MyMainClass(logger, myUsage); assertSame(logger, mainClass.getLogger()); loggerStubFactory.assertNoMoreCalls(); final String javaVersion = System.getProperty("java.version"); try { try { System.setProperty("java.version", "whatever"); new MyMainClass(logger, myUsage); fail("Expected VersionException"); } catch (VersionException e) { } loggerStubFactory.assertNoMoreCalls(); try { System.setProperty("java.version", "1.3"); new MyMainClass(logger, myUsage); fail("Expected LoggedInitialisationException"); } catch (LoggedInitialisationException e) { AssertUtilities.assertContains(e.getMessage(), "Unsupported"); loggerStubFactory.assertSuccess("error", String.class); } } finally { System.setProperty("java.version", javaVersion); } loggerStubFactory.assertNoMoreCalls(); final LoggedInitialisationException barfError = mainClass.barfError("foo"); assertEquals("foo", barfError.getMessage()); final CallData errorCall = loggerStubFactory.assertSuccess("error", String.class); AssertUtilities.assertContains(errorCall.getParameters()[0].toString(), "foo"); loggerStubFactory.assertNoMoreCalls(); final LoggedInitialisationException barfUsage = mainClass.barfUsage(); AssertUtilities.assertContains(barfUsage.getMessage(), myUsage); final CallData errorCall2 = loggerStubFactory.assertSuccess("error", String.class); AssertUtilities.assertContains(errorCall2.getParameters()[0].toString(), myUsage); loggerStubFactory.assertNoMoreCalls(); }
public void testGetType() throws Exception { final StringTextSource textSource = new StringTextSource(""); final Expectation[] wordsOfExpectation = { new Expectation(Buffer.HTML_BUFFER, "somefile/blah.htm"), new Expectation(Buffer.HTML_BUFFER, "foo.html"), new Expectation(Buffer.JAVA_BUFFER, "eieio.java"), new Expectation(Buffer.MSDOS_BATCH_BUFFER, "eat/my.shorts.bat"), new Expectation(Buffer.MSDOS_BATCH_BUFFER, "alpha.cmd"), new Expectation(Buffer.PROPERTIES_BUFFER, "essential.properties"), new Expectation(Buffer.PYTHON_BUFFER, "why/oh.py"), new Expectation(Buffer.SHELL_BUFFER, "bishbosh.bash"), new Expectation(Buffer.SHELL_BUFFER, "clishclosh.csh"), new Expectation(Buffer.SHELL_BUFFER, "kkkkrassh.ksh"), new Expectation(Buffer.SHELL_BUFFER, "be/quiet.sh"), new Expectation(Buffer.TEXT_BUFFER, "tick.txt"), new Expectation(Buffer.TEXT_BUFFER, "tech.text"), new Expectation(Buffer.XML_BUFFER, "xplicitly.xml"), new Expectation(Buffer.UNKNOWN_BUFFER, "blurb/blah"), new Expectation(Buffer.UNKNOWN_BUFFER, "fidledly.foo"), new Expectation(Buffer.UNKNOWN_BUFFER, "bah/bah"), new Expectation(Buffer.UNKNOWN_BUFFER, "...."), }; for (int i = 0; i < wordsOfExpectation.length; ++i) { final Expectation expectation = wordsOfExpectation[i]; final Buffer buffer = new BufferImplementation(s_resources, textSource, expectation.getFile()); assertEquals(expectation.getType(), buffer.getType()); assertEquals(textSource, buffer.getTextSource()); } assertEquals(Buffer.HTML_BUFFER, Buffer.HTML_BUFFER); AssertUtilities.assertNotEquals(Buffer.HTML_BUFFER, Buffer.TEXT_BUFFER); AssertUtilities.assertNotEquals(Buffer.TEXT_BUFFER, Buffer.HTML_BUFFER); AssertUtilities.assertNotEquals(Buffer.PROPERTIES_BUFFER, Buffer.UNKNOWN_BUFFER); assertEquals(Buffer.PYTHON_BUFFER, Buffer.PYTHON_BUFFER); }