mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
/*
|
|
* Copyright (c) 2010 Mysema Ltd.
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
package com.mysema.codegen;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import java.io.IOException;
|
|
import java.io.StringWriter;
|
|
import java.lang.annotation.ElementType;
|
|
|
|
import org.junit.Test;
|
|
|
|
@TestAnnotation(prop2 = false, clazz = AnnotationTest.class)
|
|
@TestAnnotation2("Hello")
|
|
@TestAnnotation3(type = ElementType.ANNOTATION_TYPE)
|
|
public class AnnotationTest {
|
|
|
|
|
|
private StringWriter w = new StringWriter();
|
|
private CodeWriter writer = new JavaWriter(w);
|
|
|
|
@Test
|
|
public void testClassAnnotation() throws IOException{
|
|
writer.annotation(getClass().getAnnotation(TestAnnotation.class));
|
|
assertEquals("@com.mysema.codegen.TestAnnotation(clazz=com.mysema.codegen.AnnotationTest.class, prop2=false)", w.toString().trim());
|
|
}
|
|
|
|
@Test
|
|
public void testClassAnnotation2() throws IOException{
|
|
writer.annotation(getClass().getAnnotation(TestAnnotation2.class));
|
|
assertEquals("@com.mysema.codegen.TestAnnotation2(\"Hello\")", w.toString().trim());
|
|
}
|
|
|
|
@Test
|
|
public void testClassAnnotation3() throws IOException{
|
|
writer.annotation(getClass().getAnnotation(TestAnnotation3.class));
|
|
assertEquals("@com.mysema.codegen.TestAnnotation3(type=java.lang.annotation.ElementType.ANNOTATION_TYPE)", w.toString().trim());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void testMethodAnnotation() throws IOException, SecurityException, NoSuchMethodException {
|
|
writer.annotation(getClass().getMethod("testMethodAnnotation").getAnnotation(Test.class));
|
|
assertEquals("@org.junit.Test", w.toString().trim());
|
|
}
|
|
|
|
@Test
|
|
public void testMin() throws IOException{
|
|
writer.annotation(new MinImpl(10));
|
|
assertEquals("@javax.validation.constraints.Min(value=10)", w.toString().trim());
|
|
}
|
|
|
|
@Test
|
|
public void testMax() throws IOException{
|
|
writer.annotation(new MaxImpl(10));
|
|
assertEquals("@javax.validation.constraints.Max(value=10)", w.toString().trim());
|
|
}
|
|
|
|
@Test
|
|
public void testNotNull() throws IOException{
|
|
writer.annotation(new NotNullImpl());
|
|
assertEquals("@javax.validation.constraints.NotNull", w.toString().trim());
|
|
}
|
|
|
|
}
|