mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
improved tests
This commit is contained in:
parent
72ebde8fb3
commit
670afe178b
@ -81,13 +81,15 @@ public final class JavaWriter implements Appendable, CodeWriter{
|
||||
public JavaWriter annotation(Annotation annotation) throws IOException {
|
||||
append(indent).append("@").appendType(annotation.annotationType()).append("(");
|
||||
boolean first = true;
|
||||
for (Method method : annotation.annotationType().getDeclaredMethods()){
|
||||
if (!first){
|
||||
append(COMMA);
|
||||
}
|
||||
append(method.getName()+"=");
|
||||
for (Method method : annotation.annotationType().getDeclaredMethods()){
|
||||
try {
|
||||
Object value = method.invoke(annotation);
|
||||
if (value == null){
|
||||
continue;
|
||||
}else if (!first){
|
||||
append(COMMA);
|
||||
}
|
||||
append(method.getName()+"=");
|
||||
annotationConstant(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CodegenException(e);
|
||||
|
||||
@ -9,6 +9,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
@ -37,6 +38,18 @@ public class JavaWriterTest {
|
||||
match("/testBasic", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterface() throws IOException{
|
||||
StringWriter w = new StringWriter();
|
||||
CodeWriter writer = new JavaWriter(w);
|
||||
writer.packageDecl("com.mysema.codegen");
|
||||
writer.imports(IOException.class, StringWriter.class, Test.class);
|
||||
writer.beginInterface("JavaWriterTest");
|
||||
writer.end();
|
||||
|
||||
match("/testInterface", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavadoc() throws IOException{
|
||||
StringWriter w = new StringWriter();
|
||||
@ -66,6 +79,36 @@ public class JavaWriterTest {
|
||||
match("/testAnnotations", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotations2() throws IOException{
|
||||
StringWriter w = new StringWriter();
|
||||
CodeWriter writer = new JavaWriter(w);
|
||||
writer.packageDecl("com.mysema.codegen");
|
||||
writer.imports(IOException.class.getPackage(), StringWriter.class.getPackage());
|
||||
writer.annotation(Entity.class);
|
||||
writer.beginClass("JavaWriterTest");
|
||||
writer.annotation(new Test(){
|
||||
@Override
|
||||
public Class<? extends Throwable> expected() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public long timeout() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return Test.class;
|
||||
}});
|
||||
writer.beginPublicMethod("void", "test");
|
||||
writer.end();
|
||||
writer.end();
|
||||
|
||||
match("/testAnnotations2", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFields() throws IOException{
|
||||
StringWriter w = new StringWriter();
|
||||
|
||||
13
src/test/resources/testAnnotations2
Normal file
13
src/test/resources/testAnnotations2
Normal file
@ -0,0 +1,13 @@
|
||||
package com.mysema.codegen;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.*;
|
||||
|
||||
@Entity
|
||||
public class JavaWriterTest {
|
||||
|
||||
@org.junit.Test(timeout=0)
|
||||
public void test() {
|
||||
}
|
||||
|
||||
}
|
||||
9
src/test/resources/testInterface
Normal file
9
src/test/resources/testInterface
Normal file
@ -0,0 +1,9 @@
|
||||
package com.mysema.codegen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
public interface JavaWriterTest {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user