@Test
  public void structuralIntegration_WcCat_GetStatusCode0() {
    String[] wcArgs = new String[] {"-m", "-"};
    ITool wcTool = new WcTool(wcArgs);
    String[] catArgs = new String[] {"-"};
    ITool catTool = new CatTool(catArgs);

    String result = wcTool.execute(new File(userDir), "this is a standard input");
    result = catTool.execute(new File(userDir), result);
    assertEquals(0, wcTool.getStatusCode());
    assertEquals(0, catTool.getStatusCode());
    assertEquals("\t24", result);
  }
  @Test
  public void structuralIntegration_EchoWc_GetStatusCode0() {
    String[] echoArgs = new String[] {"testing wc and echo together"};
    ITool echoTool = new EchoTool(echoArgs);
    String[] wcArgs = new String[] {"-w", "-"};
    ITool wcTool = new WcTool(wcArgs);

    String result = echoTool.execute(new File(userDir), "no stdin");
    result = wcTool.execute(new File(userDir), result);
    assertEquals(0, echoTool.getStatusCode());
    assertEquals(0, wcTool.getStatusCode());
    assertEquals("\t5", result);
  }
  @Test
  public void structuralIntegration_GrepWc_GetStatusCode0() {

    String[] grepArgs = new String[] {"-A", "2", "testing", "file1"};
    ITool grepTool = new GrepTool(grepArgs);
    String[] wcArgs = new String[] {"-l", "-"};
    ITool wcTool = new WcTool(wcArgs);

    String result = grepTool.execute(new File(userDir), null);
    result = wcTool.execute(new File(userDir), result);
    assertEquals(0, grepTool.getStatusCode());
    assertEquals(0, wcTool.getStatusCode());
    assertEquals("\t3", result);
  }
  @Test
  public void structuralIntegration_WcEchoError_GetStatusCodeNot0() {
    // wc no standard input when it is expected

    String[] wcArgs = new String[] {"-m", "-"};
    ITool wcTool = new WcTool(wcArgs);
    String[] echoArgs = null;
    ITool echoTool = new EchoTool(echoArgs);

    String result = wcTool.execute(new File(userDir), null);
    assertEquals(WcTool.STATUS_CODE_STDIN_EXPECTED, wcTool.getStatusCode());

    result = echoTool.execute(new File(userDir), result);
    assertEquals(0, echoTool.getStatusCode());
  }
  @Test
  public void structuralIntegration_CatWcError_GetStatusCodeNot0() {
    // cat file does not exist

    String[] catArgs = new String[] {"fileNotExist"};
    ITool catTool = new CatTool(catArgs);
    String[] wcArgs = new String[] {"-l", "-"};
    ITool wcTool = new WcTool(wcArgs);

    String result = catTool.execute(new File(userDir), null);
    assertEquals(CatTool.ERR_CODE_FILE_NOT_FOUND, catTool.getStatusCode());

    // error message from cat passed to wc
    result = wcTool.execute(new File(userDir), result);
    assertEquals(0, wcTool.getStatusCode());
  }
Exemplo n.º 6
0
  @Override
  public void run() {

    File workingDir = new File(System.getProperty("user.dir"));
    String result = tool.execute(workingDir, stdIn);
    if (!result.isEmpty()) {
      if (!Shell.underTest) System.out.println(result);
      Shell.result = result;
    } else Shell.result = "";
    if (!Shell.underTest) System.out.print(System.getProperty("user.dir") + " >> ");
  }