Ejemplo n.º 1
0
  public void testWriteConstructors() throws Exception {
    final Subclasser sub = new Subclasser();
    Protectable p =
        new Protectable() {
          public void protect() throws Exception {
            sub.writeConstructors();
          }
        };

    chkException(p, null);

    sub.setParentClass(javax.sql.DataSource.class);
    chkException(p, "interface");

    sub.setParentClass(com.p6spy.engine.spy.P6DataSource.class);
    String expected =
        ""
            + sub.NEWLINE
            + sub.INDENT
            + "public P6P6DataSource (javax.sql.DataSource p0) {"
            + sub.NEWLINE
            + sub.INDENT
            + sub.INDENT
            + "super( p0);"
            + sub.NEWLINE
            + sub.INDENT
            + "}"
            + sub.NEWLINE
            + sub.INDENT
            + "public P6P6DataSource () {"
            + sub.NEWLINE
            + sub.INDENT
            + sub.INDENT
            + "super();"
            + sub.NEWLINE
            + sub.INDENT
            + "}"
            + "";
    String actual = sub.writeConstructors();

    assertEquals(expected, actual);
    // sometimes JUnit truncs the strings... if that's the case with your
    // version, then you can uncomment this line to get out own
    // full listing of the strings in their variance
    // assertEquals("Expected constructor like: " + sub.NEWLINE + expected + sub.NEWLINE + " but
    // found " + sub.NEWLINE + actual + sub.NEWLINE, expected, actual);
  }
Ejemplo n.º 2
0
  public void testBadClass() throws Exception {
    final Subclasser sub = new Subclasser();
    // Protectable is JUnit class
    Protectable p =
        new Protectable() {
          public void protect() throws Exception {
            sub.createSubClass();
          }
        };

    chkException(p, "must not be null");

    sub.setParentClass(this.getClass());
    chkException(p, "instanceof javax.sql.DataSource");
  }
Ejemplo n.º 3
0
  public void testWriteHeader() throws Exception {
    final Subclasser sub = new Subclasser();
    // Protectable is JUnit class
    Protectable p =
        new Protectable() {
          public void protect() throws Exception {
            sub.writeHeader();
          }
        };

    chkException(p, null);

    sub.setParentClass(com.p6spy.engine.spy.P6DataSource.class);
    String actual = sub.writeHeader();

    // com.p6spy.engine.spy is imported twice since
    // we're sublcassing the p6spy datasource.
    String expected =
        ""
            + "// this class generated by class com.p6spy.engine.common.Subclasser"
            + sub.NEWLINE
            + sub.NEWLINE
            + "package "
            + sub.DEFAULT_PACKAGE
            + ";"
            + sub.NEWLINE
            + sub.NEWLINE
            + "import com.p6spy.engine.spy.*;"
            + sub.NEWLINE
            + "import java.sql.*;"
            + sub.NEWLINE
            + "import javax.sql.*;"
            + sub.NEWLINE
            + "import com.p6spy.engine.spy.*;"
            + sub.NEWLINE
            + sub.NEWLINE
            + sub.NEWLINE
            + "public class P6P6DataSource extends com.p6spy.engine.spy.P6DataSource {"
            + sub.NEWLINE
            + "";

    assertEquals(sub.NEWLINE + expected, sub.NEWLINE + actual);
  }