improved tests

This commit is contained in:
Timo Westkämper 2010-04-26 11:20:05 +00:00
parent 72ebde8fb3
commit 670afe178b
4 changed files with 72 additions and 5 deletions

View File

@ -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);

View File

@ -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();

View 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() {
}
}

View File

@ -0,0 +1,9 @@
package com.mysema.codegen;
import java.io.IOException;
import java.io.StringWriter;
import org.junit.Test;
public interface JavaWriterTest {
}