// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/message/Message.java
// public class Message<T> {
// 
//     final private Object source;
// 
//     final private String method;
// 
//     final private T payload;
// 
//     public Message(Object source, String method, T payload) {
//         this.source = source;
//         this.method = method;
//         this.payload = payload;
//     }
// 
//     public Object getSource() {
//         return source;
//     }
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuffer sb = new StringBuffer();
//         sb.append(this.getClass().getSimpleName().toString())
// //                .append(String.valueOf(source))
//                 .append(".")
//                 .append(method);
// 
//         return sb.toString();
//     }
// }
// 
// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/message/OnErrorMessage.java
// public class OnErrorMessage extends Message<Throwable> {
// 
//     public OnErrorMessage(Object source, String method, Throwable payload) {
//         super(source, method, payload);
//     }
// 
//     @Override
//     public String toString() {
//         return super.toString() + ": threw " + getPayload().toString();
//     }
// }
// 
// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/test/TestBase.java
// public class TestBase {
// 
//     public static final int NUMBER_OF_ENTRIES_PER_TRACED_PARAMETER = 2; // first value should be the name, the second one is the value of the parameter
// 
//     @BeforeClass
//     public static void setup() {
//         // switch to the in-memory implementation, so we can do unit testing.
//         GhostWriter.setTracerProvider(InMemoryTracerProvider.INSTANCE);
//     }
// 
//     @Before
//     public void configureInMemoryTracer() {
//         fetchedPreparedInMemoryTracer();
//     }
// 
//     //FIXME(snorbi07): refactor to a more meaningful name... the difficulty is coming up with one
//     public InMemoryTracer fetchedPreparedInMemoryTracer() {
//         InMemoryTracer tracer = InMemoryTracerProvider.INSTANCE.getTracer();
//         // we only need value change tracker in the specific tests and there we enable it manually
//         tracer.disableValueChangeTracking();
//         // make sure that entering/exiting tracing is enabled.
//         tracer.enableEnteringExitingTracking();
//         // we clear manually because the @Test method is also traced and it pollutes the entering logs.
//         tracer.clearMessages();
// 
//         return tracer;
//     }
// 
//     public void disableValueChangeTracking() {
//         InMemoryTracerProvider.INSTANCE.getTracer().disableValueChangeTracking();
//     }
// 
//     public void enableValueChangeTracking() {
//         InMemoryTracerProvider.INSTANCE.getTracer().enableValueChangeTracking();
//     }
// 
// }


import io.ghostwriter.message.Message;
import io.ghostwriter.message.OnErrorMessage;
import io.ghostwriter.test.TestBase;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
package io.ghostwriter;



public class OnErrorTest extends TestBase {

    @Test
    public void testDereferenceNull() {
        InMemoryTracer inMemoryTracer = fetchedPreparedInMemoryTracer();
        boolean expectedExceptionTypeCaught = false;
        try {
            dereferenceNull();
        }
        catch (NullPointerException e) { // we intentionally throw a NPE and catch it to see whether it is logged by GW.
            expectedExceptionTypeCaught = true;
        }
        assertTrue("Expected error did not occur", expectedExceptionTypeCaught);

        // pop the unused exitingMessage triggered by "dereferenceNull" call
        inMemoryTracer.popMessage();

        Message<?> onErrorMessage = inMemoryTracer.popMessage();
        // verify message type
// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/message/Message.java
// public class Message<T> {
// 
//     final private Object source;
// 
//     final private String method;
// 
//     final private T payload;
// 
//     public Message(Object source, String method, T payload) {
//         this.source = source;
//         this.method = method;
//         this.payload = payload;
//     }
// 
//     public Object getSource() {
//         return source;
//     }
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuffer sb = new StringBuffer();
//         sb.append(this.getClass().getSimpleName().toString())
// //                .append(String.valueOf(source))
//                 .append(".")
//                 .append(method);
// 
//         return sb.toString();
//     }
// }
// 
// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/message/OnErrorMessage.java
// public class OnErrorMessage extends Message<Throwable> {
// 
//     public OnErrorMessage(Object source, String method, Throwable payload) {
//         super(source, method, payload);
//     }
// 
//     @Override
//     public String toString() {
//         return super.toString() + ": threw " + getPayload().toString();
//     }
// }
// 
// Path: ghostwriter-test-java-v7/src/main/java/io/ghostwriter/test/TestBase.java
// public class TestBase {
// 
//     public static final int NUMBER_OF_ENTRIES_PER_TRACED_PARAMETER = 2; // first value should be the name, the second one is the value of the parameter
// 
//     @BeforeClass
//     public static void setup() {
//         // switch to the in-memory implementation, so we can do unit testing.
//         GhostWriter.setTracerProvider(InMemoryTracerProvider.INSTANCE);
//     }
// 
//     @Before
//     public void configureInMemoryTracer() {
//         fetchedPreparedInMemoryTracer();
//     }
// 
//     //FIXME(snorbi07): refactor to a more meaningful name... the difficulty is coming up with one
//     public InMemoryTracer fetchedPreparedInMemoryTracer() {
//         InMemoryTracer tracer = InMemoryTracerProvider.INSTANCE.getTracer();
//         // we only need value change tracker in the specific tests and there we enable it manually
//         tracer.disableValueChangeTracking();
//         // make sure that entering/exiting tracing is enabled.
//         tracer.enableEnteringExitingTracking();
//         // we clear manually because the @Test method is also traced and it pollutes the entering logs.
//         tracer.clearMessages();
// 
//         return tracer;
//     }
// 
//     public void disableValueChangeTracking() {
//         InMemoryTracerProvider.INSTANCE.getTracer().disableValueChangeTracking();
//     }
// 
//     public void enableValueChangeTracking() {
//         InMemoryTracerProvider.INSTANCE.getTracer().enableValueChangeTracking();
//     }
// 
// }


// Path: ghostwriter-test-java-v7/src/test/java/io/ghostwriter/OnErrorTest.java
import io.ghostwriter.message.Message;
import io.ghostwriter.message.OnErrorMessage;
import io.ghostwriter.test.TestBase;
import org.junit.Test;
import static org.junit.Assert.assertTrue;

package io.ghostwriter;



public class OnErrorTest extends TestBase {

    @Test
    public void testDereferenceNull() {
        InMemoryTracer inMemoryTracer = fetchedPreparedInMemoryTracer();
        boolean expectedExceptionTypeCaught = false;
        try {
            dereferenceNull();
        }
        catch (NullPointerException e) { // we intentionally throw a NPE and catch it to see whether it is logged by GW.
            expectedExceptionTypeCaught = true;
        }
        assertTrue("Expected error did not occur", expectedExceptionTypeCaught);

        // pop the unused exitingMessage triggered by "dereferenceNull" call
        inMemoryTracer.popMessage();

        Message<?> onErrorMessage = inMemoryTracer.popMessage();
        // verify message type
        assertTrue("Invalid message type: " + onErrorMessage.getClass(), onErrorMessage instanceof OnErrorMessage);