package com.skraylabs.poker;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class ApplicationTest {

  private static final String MSG_TOO_FEW_ARGS = "Too few arguments";
  private static final String MSG_TOO_MANY_ARGS = "Too many arguments";
  private static final String MSG_USAGE = "Usage: PokerCalculator filepath";

  /**
   * Output stream from Application.main() for test verification.
   */
  private ByteArrayOutputStream output;

  /**
   * Temporary reference to System.out
   */
  private PrintStream console;

  @Before
  public void setUp() throws Exception {
    output = new ByteArrayOutputStream();
    console = System.out;
    System.setOut(new PrintStream(output));
  }

  @After
  public void tearDown() throws Exception {
    System.setOut(console);    
  }

  @Test
  public void testShowUsageForTooFewArguments() {
    // Exercise
    Application.main();
    // Verify
    String outputString = output.toString();
    assertThat(outputString, allOf(containsString(MSG_TOO_FEW_ARGS),
        containsString(MSG_USAGE)));
  }

}

@@ -1300,10 +1300,288 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void testShowUsageForTooManyArguments() %7B%0A    // Exercise%0A    Application.main(%221%22, %222%22);%0A    // Verify%0A    String outputString = output.toString();%0A    assertThat(outputString, allOf(containsString(MSG_TOO_MANY_ARGS),%0A        containsString(MSG_USAGE)));%0A  %7D%0A%0A
 %7D%0A

Add application test for “too many arguments”.