Cowsay { public static String say(final String[] args) { return sayOrThink(args, false); } private  Cowsay(); static String say(final String[] args); static String think(final String[] args); static void main(final String[] args);  }
@Test public void testSay() { System.out.println("cowsay Hello"); String[] args = new String[]{"Hello"}; String expResult = TestUtils.loadExpected("cowsayHello.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayHtml() { System.out.println("cowsay --html --alt \"A cow saying 'Hello'\""); String[] args = new String[]{"--html", "--alt", "A cow saying 'Hello'", "Hello"}; String expResult = TestUtils.loadExpected("cowsayHelloHtml.html"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayWhitespaceNormalized() { System.out.println("cowsay \"\t\tHello there \t\t \""); String[] args = new String[]{"\t\tHello there \t\t "}; String expResult = TestUtils.loadExpected("cowsayWhitespace.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testPipedSay() { try { System.out.println("echo Hello | cowsay"); String[] args = new String[0]; ByteArrayInputStream in = new ByteArrayInputStream("Hello".getBytes()); System.setIn(in); String expResult = TestUtils.loadExpected("cowsayHello.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); } finally { System.setIn(System.in); } }
@Test public void testPipedSayTrumpedByArgs() { try { System.out.println("echo foobar | cowsay Hello"); String[] args = new String[]{"Hello"}; String expResult = TestUtils.loadExpected("cowsayHello.txt"); ByteArrayInputStream in = new ByteArrayInputStream("foobar".getBytes()); System.setIn(in); String result = Cowsay.say(args); Assert.assertEquals("Message from args trumps piped input", expResult, result); } finally { System.setIn(System.in); } }
@Test public void testSayManyWords() { System.out.println("cowsay foo bar baz"); String[] args = new String[]{"foo", "bar", "baz"}; String expResult = TestUtils.loadExpected("cowsayFooBarBaz.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayManyWordsOneArg() { System.out.println("cowsay foo bar baz"); String[] args = new String[]{"foo bar baz"}; String expResult = TestUtils.loadExpected("cowsayFooBarBaz.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testPipedSayManyWords() { try { System.out.println("echo foo bar baz | cowsay"); String expResult = TestUtils.loadExpected("cowsayFooBarBaz.txt"); String[] args = new String[0]; ByteArrayInputStream in = new ByteArrayInputStream("foo bar baz".getBytes()); System.setIn(in); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); } finally { System.setIn(System.in); } }
@Test public void testCowthinkArg() { System.out.println("cowsay --cowthink Hello"); String[] args = new String[]{"--cowthink", "Hello"}; String expResult = TestUtils.loadExpected("cowthinkHello.txt"); CowsayCli.addCowthinkOption(); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayWrap2() { System.out.println("cowsay -W 2 Hello"); String[] args = new String[]{"-W", "2", "Hello"}; String expResult = TestUtils.loadExpected("cowsayWrap2.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayNowrap() { System.out.println("cowsay -n msg"); String[] args = new String[]{"-n", "Moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo"}; String expResult = TestUtils.loadExpected("cowsayLong.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayWrapZero() { System.out.println("cowsay -W 0 msg"); String[] args = new String[]{"-W", "0", "Moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo"}; String expResult = TestUtils.loadExpected("cowsayLong.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayWithNamedFile() { System.out.println("cowsay -f tux Hello"); String[] args = new String[]{"-f", "tux", "Hello"}; String expResult = TestUtils.loadExpected("cowsayTux.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayWithNamedFileNotFound() { System.out.println("cowsay -f abcdefgzzzblah Hello"); String[] args = new String[]{"-f", "abcdefgzzzblah", "Hello"}; String expResult = TestUtils.loadExpected("cowsayHello.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayModes() { Set<String> modes = modeMap.keySet(); for (String key : modes) { String[] args = new String[]{'-' + key, "Hello"}; System.out.println("cowsay -" + key + " Hello"); String expResult = TestUtils.loadExpected(modeMap.get(key)); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); } }
@Test public void testSayModesPiped() { try { Set<String> modes = modeMap.keySet(); for (String key : modes) { String[] args = new String[]{'-' + key}; System.out.println("echo Hello | cowsay -" + key); String expResult = TestUtils.loadExpected(modeMap.get(key)); ByteArrayInputStream in = new ByteArrayInputStream("Hello".getBytes()); System.setIn(in); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); } } finally { System.setIn(System.in); } }
@Test public void testSayEyes() { System.out.println("-e QQ cowsay"); String[] args = new String[]{"-e", "QQ", "Hello"}; String expResult = TestUtils.loadExpected("cowsayEyes.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayEyesDollars() { System.out.println("-e $$ cowsay"); String[] args = new String[]{"-e", "$$", "Hello"}; String expResult = TestUtils.loadExpected("cowsayGreedy.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayEyesBackslash() { System.out.println("-e \\\\ cowsay"); String[] args = new String[]{"-e", "\\\\", "Hello"}; String expResult = TestUtils.loadExpected("cowsayEyesBackslash.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayTongue() { System.out.println("-T V cowsay"); String[] args = new String[]{"-T", "V", "Hello"}; String expResult = TestUtils.loadExpected("cowsayTongue.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayTongueEyes() { System.out.println("cowsay -T V -e QQ Hello"); String[] args = new String[]{"-T", "V", "-e", "QQ", "Hello"}; String expResult = TestUtils.loadExpected("cowsayTongueEyes.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayLongLine() { System.out.println("cowsay long"); String[] args = new String[]{"Moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo moo"}; String expResult = TestUtils.loadExpected("cowsayMulti.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayMultiLineInput() { System.out.println("cowsay mutli"); String[] args = new String[]{"This is a test text." + System.getProperty("line.separator") + "To test long lines in cowsay." + System.getProperty("line.separator") + "Moo moo moo."}; String expResult = TestUtils.loadExpected("cowsayMultiline.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }
@Test public void testSayMultiLineLongInput() { System.out.println("cowsay mutli long"); String[] args = new String[]{"This is a test text." + System.lineSeparator() + "To test long lines in cowsay." + System.lineSeparator() + "This is a really really really really really long line." + System.lineSeparator() + "Moo moo moo."}; String expResult = TestUtils.loadExpected("cowsayMultilineLong.txt"); String result = Cowsay.say(args); TestUtils.cowfileCompare(expResult, result); }