Example #1
0
  protected void compareFiles(Subclasser sub) throws Exception {
    sub.createSubClass();
    String name = sub.getOutputName();

    File expected = new File("etc", name + ".java");
    File actual = sub.getOutputFile();

    compareFiles(expected, actual);
  }
Example #2
0
  public void testString() throws Exception {
    Subclasser sub = new Subclasser();
    Class clazz = this.getClass();
    String packageName = clazz.getPackage().getName();
    String className = clazz.getName();

    // NB, this will all break if you change the package structure :)
    // pretty unlikely, but just in case it starts to fail, keep it in mind
    String expectedName = "P6TestSubclasser";
    assertEquals(expectedName, sub.baseName(className));

    // this one's a little trickier... since it could fail
    // depending on your architecture.  So put in this terrible
    // switchlike hack here
    String expectedPath = null;

    if (sub.DELIMITER.equals("/")) {
      expectedPath = "com/p6spy/engine/test";
    } else if (sub.DELIMITER.equals("\\")) {
      expectedPath = "com\\p6spy\\engine\\test";
    } else if (sub.DELIMITER.equals(":")) {
      expectedPath = "com:p6spy:engine:test";
    }

    if (expectedPath == null) {
      fail(
          "Unexpected file separator: "
              + sub.DELIMITER
              + ". Please expand the test class to test for this file separator.");
    }

    assertEquals(expectedPath, sub.packToDir(packageName));

    // now check the default file
    String newName = "ThisIsATestClass";

    sub.setOutputPackage(packageName);
    sub.setOutputName(newName);

    File actualFile = sub.getOutputFile();
    File expectedFile = new File("scratch" + sub.DELIMITER + expectedPath, newName + ".java");

    assertEquals(expectedFile, actualFile);
  }