add tests for enabling note logging

This commit is contained in:
Zoltán Reegn 2017-04-03 22:41:41 +02:00 committed by Zoltán Reegn
parent d92743ec29
commit f52c728f15
2 changed files with 73 additions and 2 deletions

View File

@ -66,8 +66,8 @@ public abstract class AbstractProcessorTest {
options.addAll(getAPTOptions());
options.addAll(classes);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
ByteArrayOutputStream out = getStdOut();
ByteArrayOutputStream err = getStdErr();
int compilationResult = compiler.run(null, out, err, options.toArray(new String[options.size()]));
// Processor.elementCache.clear();
@ -77,6 +77,14 @@ public abstract class AbstractProcessorTest {
}
}
protected ByteArrayOutputStream getStdOut() {
return new ByteArrayOutputStream();
}
protected ByteArrayOutputStream getStdErr() {
return new ByteArrayOutputStream();
}
protected Collection<String> getAPTOptions() {
return Collections.emptyList();
}

View File

@ -0,0 +1,63 @@
package com.querydsl.apt;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
public class NoteTest extends AbstractProcessorTest {
private Collection<String> aptOptions;
private ByteArrayOutputStream err = new ByteArrayOutputStream();
private static final String packagePath = "src/test/java/com/querydsl/apt/";
public void process() throws IOException {
List<String> classes = getFiles(packagePath);
process(QuerydslAnnotationProcessor.class, classes, "includedClasses");
}
@Override
protected Collection<String> getAPTOptions() {
return aptOptions;
}
@Override
protected ByteArrayOutputStream getStdErr() {
return err;
}
protected boolean isStdErrEmpty() {
return getStdErr().toByteArray().length == 0;
}
@Test
public void processDefault() throws IOException {
aptOptions = Collections.emptyList();
process();
assertTrue(isStdErrEmpty());
}
@Test
public void processEnabled() throws IOException {
aptOptions = Arrays.asList("-Aquerydsl.logInfo=true");
process();
assertFalse(isStdErrEmpty());
}
@Test
public void processDisabled() throws IOException {
aptOptions = Arrays.asList("-Aquerydsl.logInfo=false");
process();
assertTrue(isStdErrEmpty());
}
}