public void testInstrumentWithDefaults() throws Exception {
    final MasterInstrumenter masterInstrumenter =
        new MasterInstrumenter(m_loggerStubFactory.getLogger(), false);

    assertEquals(
        "traditional Jython instrumenter; " + "byte code transforming instrumenter for Java",
        masterInstrumenter.getDescription());

    m_loggerStubFactory.assertOutputMessageContains("traditional Jython");
    m_loggerStubFactory.assertNoMoreCalls();

    try {
      masterInstrumenter.instrument(null, m_recorder, null);
      fail("Expected NonInstrumentableTypeException");
    } catch (NonInstrumentableTypeException e) {
    }

    final Object foo = new Object();

    try {
      masterInstrumenter.instrument(m_test, m_recorder, foo);
      fail("Expected NonInstrumentableTypeException");
    } catch (NonInstrumentableTypeException e) {
    }
  }
  public void testCreateInstrumentedProxyWithDefaults() throws Exception {
    final MasterInstrumenter masterInstrumenter =
        new MasterInstrumenter(m_loggerStubFactory.getLogger(), false);

    assertEquals(
        "traditional Jython instrumenter; " + "byte code transforming instrumenter for Java",
        masterInstrumenter.getDescription());

    m_loggerStubFactory.assertOutputMessageContains("traditional Jython");
    m_loggerStubFactory.assertNoMoreCalls();

    try {
      masterInstrumenter.createInstrumentedProxy(null, m_recorder, null);
      fail("Expected NotWrappableTypeException");
    } catch (NotWrappableTypeException e) {
    }

    final Object foo = new Object();

    final PyObject proxy =
        (PyObject) masterInstrumenter.createInstrumentedProxy(m_test, m_recorder, foo);

    assertSame(proxy.__getattr__("__target__").__tojava__(Object.class), foo);

    try {
      masterInstrumenter.createInstrumentedProxy(m_test, m_recorder, new PyObject());
      fail("Expected NotWrappableTypeException");
    } catch (NotWrappableTypeException e) {
    }
  }
  public void testWithForcedDCRInsstrumentation() throws Exception {
    final MasterInstrumenter masterInstrumenter =
        new MasterInstrumenter(m_loggerStubFactory.getLogger(), true);

    assertEquals(
        "byte code transforming instrumenter for Jython 2.1/2.2; "
            + "byte code transforming instrumenter for Java",
        masterInstrumenter.getDescription());

    m_loggerStubFactory.assertOutputMessageContains("byte code");
    m_loggerStubFactory.assertNoMoreCalls();
  }
Exemplo n.º 4
0
  public void testAbstractMainClass() throws Exception {

    final LoggerStubFactory loggerStubFactory = new LoggerStubFactory();
    final Logger logger = loggerStubFactory.getLogger();
    final String myUsage = "do some stuff";

    final MyMainClass mainClass = new MyMainClass(logger, myUsage);

    assertSame(logger, mainClass.getLogger());

    loggerStubFactory.assertNoMoreCalls();

    final String javaVersion = System.getProperty("java.version");

    try {
      try {
        System.setProperty("java.version", "whatever");
        new MyMainClass(logger, myUsage);
        fail("Expected VersionException");
      } catch (VersionException e) {
      }

      loggerStubFactory.assertNoMoreCalls();

      try {
        System.setProperty("java.version", "1.3");
        new MyMainClass(logger, myUsage);
        fail("Expected LoggedInitialisationException");
      } catch (LoggedInitialisationException e) {
        AssertUtilities.assertContains(e.getMessage(), "Unsupported");
        loggerStubFactory.assertSuccess("error", String.class);
      }
    } finally {
      System.setProperty("java.version", javaVersion);
    }

    loggerStubFactory.assertNoMoreCalls();

    final LoggedInitialisationException barfError = mainClass.barfError("foo");
    assertEquals("foo", barfError.getMessage());
    final CallData errorCall = loggerStubFactory.assertSuccess("error", String.class);
    AssertUtilities.assertContains(errorCall.getParameters()[0].toString(), "foo");
    loggerStubFactory.assertNoMoreCalls();

    final LoggedInitialisationException barfUsage = mainClass.barfUsage();
    AssertUtilities.assertContains(barfUsage.getMessage(), myUsage);
    final CallData errorCall2 = loggerStubFactory.assertSuccess("error", String.class);
    AssertUtilities.assertContains(errorCall2.getParameters()[0].toString(), myUsage);
    loggerStubFactory.assertNoMoreCalls();
  }