/**
   * Test whether output routines work as expected. This is done by comparing generating output on a
   * file "useOutput.txt" and comparing it to a file "expectedOutput.txt". On a first run this test
   * might break because the file "expectedOutput.txt" does not exist. Then just run the test,
   * verify manually whether "useOutput.txt" conforms to the expected output and if it does rename
   * "useOutput.txt" in "expectedOutput.txt". From then on the tests should work as expected.
   */
  public void testOutput() {
    Network network = Network.DefaultExample();
    String generateOutputFName = "useOutput.txt", expectedOutputFName = "expectedOutput.txt";
    FileWriter generateOutput;
    StringBuffer buf = new StringBuffer(500);
    StringWriter report = new StringWriter(500);

    try {
      generateOutput = new FileWriter(generateOutputFName);
    } catch (IOException f2exc) {
      assertTrue("Could not create '" + generateOutputFName + "'", false);
      return;
    }
    ;

    try {
      buf.append(
          "---------------------------------ASCII------------------------------------------\n");
      network.printOn(buf);
      buf.append(
          "\n\n---------------------------------HTML------------------------------------------\n");
      network.printHTMLOn(buf);
      buf.append(
          "\n\n---------------------------------XML------------------------------------------\n");
      network.printXMLOn(buf);
      generateOutput.write(buf.toString());
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success --------------------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (UnkownPrinter) ------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "UnknownPrinter", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Workstation) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Node) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "n1", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Failure Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Broadcast Success -----------------\n");
      network.requestBroadcast(report);
      generateOutput.write(report.toString());
    } catch (IOException exc) {
    } finally {
      try {
        generateOutput.close();
      } catch (IOException exc) {
      }
      ;
    }
    ;
    assertTrue(
        "Generated output is not as expected ",
        compareFiles(generateOutputFName, expectedOutputFName));
  }
  private void YOUMAYWANTTOtestCompareFiles() {
    String fName1 = "testCompare1.txt",
        fName2 = "testCompare2.txt",
        fName3 = "testCompare3.txt",
        fName4 = "testCompare4.txt";
    FileWriter f1, f2, f3, f4;

    try {
      f1 = new FileWriter(fName1);
      try {
        f2 = new FileWriter(fName2);
        try {
          f3 = new FileWriter(fName3);
          try {
            f4 = new FileWriter(fName4);
          } catch (IOException f3exc) {
            try {
              f1.close();
            } catch (IOException exc) {
            }
            ;
            try {
              f2.close();
            } catch (IOException exc) {
            }
            ;
            try {
              f3.close();
            } catch (IOException exc) {
            }
            ;
            return;
          }
        } catch (IOException f3exc) {
          try {
            f1.close();
          } catch (IOException exc) {
          }
          ;
          try {
            f2.close();
          } catch (IOException exc) {
          }
          ;
          return;
        }
      } catch (IOException f2exc) {
        try {
          f1.close();
        } catch (IOException exc) {
        }
        ;
        return;
      }
    } catch (IOException f1exc) {
      return;
    }
    ;

    try {
      f1.write("aaa");
      f2.write("aaa");
      f3.write("aa");
      f4.write("aab");
    } catch (IOException exc) {
    } finally {
      try {
        f1.close();
      } catch (IOException exc) {
      }
      ;
      try {
        f2.close();
      } catch (IOException exc) {
      }
      ;
      try {
        f3.close();
      } catch (IOException exc) {
      }
      ;
      try {
        f4.close();
      } catch (IOException exc) {
      }
      ;
    }

    assertTrue("equals fName1 to fName2 ", compareFiles(fName1, fName2));
    assertFalse("not equals fName1 to fName3 (fName 3 is shorter)", compareFiles(fName1, fName3));
    assertFalse("not equals fName3 to fName1  (fName 3 is shorter)", compareFiles(fName3, fName1));
    assertFalse(
        "not equals fName1 to fName4 (last character differs)", compareFiles(fName1, fName4));
    assertFalse(
        "not equals fName1 to fName4 (last character differs)", compareFiles(fName1, fName4));
  }