package com.github.mttkay.memento;

import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;

import com.google.testing.compile.CompilationFailureException;
import com.google.testing.compile.JavaFileObjects;
import com.sun.tools.internal.xjc.util.NullStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.truth0.Truth;

import java.io.PrintStream;

@RunWith(JUnit4.class)
public class MementoProcessorTest {

    @Before
    public void dontPrintExceptions() {
        // get rid of the stack trace prints for expected exceptions
        System.setErr(new PrintStream(new NullStream()));
    }

    @Test
    public void generateMementoClass() {
        Truth.ASSERT.about(javaSource())
                .that(JavaFileObjects.forResource("RetainedActivity.java"))
                .processedWith(new MementoProcessor())
                .compilesWithoutError()
                .and().generatesSources(JavaFileObjects.forResource("RetainedActivity$Memento.java"));
    }

    @Test(expected = CompilationFailureException.class)
    public void throwsIllegalStateIfRetainedFieldIsPrivate() {
        Truth.ASSERT.about(javaSource())
                .that(JavaFileObjects.forResource("RetainedActivityWithPrivateFields.java"))
                .processedWith(new MementoProcessor())
                .failsToCompile();
    }
}

@@ -718,23 +718,34 @@
 oid 
-g
+itG
 enerate
+s
 Memento
+Fragment
 Clas
@@ -1148,28 +1148,29 @@
 oid 
-t
+itT
 hrows
-IllegalStateIf
+ExceptionWhen
 Reta

Move to spec inspired test names (truth always wins.)