Skip to content

Commit

Permalink
add tests showing what happens when annotation names are omitted
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenson authored and lincolnthree committed Jan 4, 2013
1 parent 8df122d commit 436f4c1
Showing 1 changed file with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public void testAddAnnotation() throws Exception
assertEquals("RequestScoped", annotation.getName());
}

@Test
public void testAddAnonymousAnnotation() throws Exception
{
int size = target.getAnnotations().size();
Annotation<O> annotation = target.addAnnotation();
List<Annotation<O>> annotations = target.getAnnotations();
assertEquals(size + 1, annotations.size());
assertEquals(annotation, target.getAnnotations().get(size));
assertEquals("@MISSING", annotation.toString());
}

@Test
public void testAddAnnotationByClass() throws Exception
{
Expand Down Expand Up @@ -179,6 +190,37 @@ public void testAddNestedAnnotationNameValue() throws Exception
assertEquals("baz", nested.getStringValue("bar"));
}

@Test
public void testAddNestedAnonymousAnnotationValue() throws Exception
{
target.addAnnotation(Test.class).setAnnotationValue()
.setEnumValue(ElementType.FIELD, ElementType.METHOD);

List<Annotation<O>> annotations = target.getAnnotations();

Annotation<O> annotation = annotations.get(annotations.size() - 1);
assertEquals("@MISSING({ElementType.FIELD,ElementType.METHOD})", annotation.getLiteralValue());

Annotation<O> nested = annotation.getAnnotationValue();
assertEquals("MISSING", nested.getName());
assertEquals("{ElementType.FIELD,ElementType.METHOD}", nested.getLiteralValue());
}

@Test
public void testAddNestedAnonymousAnnotationNameValue() throws Exception
{
target.addAnnotation(Test.class).setAnnotationValue("foo").setStringValue("bar", "baz");

List<Annotation<O>> annotations = target.getAnnotations();

Annotation<O> annotation = annotations.get(annotations.size() - 1);
assertEquals("@MISSING(bar=\"baz\")", annotation.getLiteralValue("foo"));

Annotation<O> nested = annotation.getAnnotationValue("foo");
assertEquals("MISSING", nested.getName());
assertEquals("baz", nested.getStringValue("bar"));
}

@Test
public void testAddDeeplyNestedAnnotationValue() throws Exception
{
Expand Down Expand Up @@ -210,7 +252,38 @@ public void testAddDeeplyNestedAnnotationNameValue() throws Exception
assertEquals("com.test.Bar", deeplyNested.getName());
assertTrue(deeplyNested.isMarker());
}


@Test
public void testAddDeeplyNestedAnonymousAnnotationValue() throws Exception
{
target.addAnnotation(Test.class).setAnnotationValue().setName("com.test.Foo")
.setAnnotationValue();

List<Annotation<O>> annotations = target.getAnnotations();

Annotation<O> annotation = annotations.get(annotations.size() - 1);
assertEquals("@com.test.Foo(@MISSING)", annotation.getLiteralValue());

Annotation<O> deeplyNested = annotation.getAnnotationValue().getAnnotationValue();
assertEquals("MISSING", deeplyNested.getName());
assertTrue(deeplyNested.isMarker());
}

@Test
public void testAddDeeplyNestedAnonymousAnnotationNameValue() throws Exception
{
target.addAnnotation(Test.class).setAnnotationValue("foo").setName("com.test.Foo").setAnnotationValue("bar");

List<Annotation<O>> annotations = target.getAnnotations();

Annotation<O> annotation = annotations.get(annotations.size() - 1);
assertEquals("@com.test.Foo(bar=@MISSING)", annotation.getLiteralValue("foo"));

Annotation<O> deeplyNested = annotation.getAnnotationValue("foo").getAnnotationValue("bar");
assertEquals("MISSING", deeplyNested.getName());
assertTrue(deeplyNested.isMarker());
}

@Test
public void testAddLiteralValue() throws Exception
{
Expand Down

0 comments on commit 436f4c1

Please sign in to comment.