package fi.evident.apina.spring.java.model;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class JavaAnnotationTest {

    @Test
    public void toStringWithoutParameters() {
        JavaAnnotation annotation = new JavaAnnotation(new QualifiedName("foo.bar.Baz"));
        assertThat(annotation.toString(), is("@foo.bar.Baz"));
    }

    @Test
    public void toStringWithJustValue() {
        JavaAnnotation annotation = new JavaAnnotation(new QualifiedName("foo.bar.Baz"));
        annotation.setAttribute("value", 42);

        assertThat(annotation.toString(), is("@foo.bar.Baz(42)"));
    }

    @Test
    public void toStringWithNonValueAttribute() {
        JavaAnnotation annotation = new JavaAnnotation(new QualifiedName("foo.bar.Baz"));
        annotation.setAttribute("foo", 42);

        assertThat(annotation.toString(), is("@foo.bar.Baz(foo=42)"));
    }

    @Test
    public void toStringWithMultipleAttributes() {
        JavaAnnotation annotation = new JavaAnnotation(new QualifiedName("foo.bar.Baz"));
        annotation.setAttribute("value", 1);
        annotation.setAttribute("foo", 2);
        annotation.setAttribute("bar", 3);

        assertThat(annotation.toString(), is("@foo.bar.Baz(value=1, foo=2, bar=3)"));
    }
}

@@ -272,37 +272,32 @@
 annotation = new
- Java
 Annotation(new Q
@@ -291,34 +291,16 @@
 otation(
-new QualifiedName(
 %22foo.bar
@@ -297,33 +297,32 @@
 n(%22foo.bar.Baz%22)
-)
 ;%0A        assert
@@ -460,37 +460,32 @@
 annotation = new
- Java
 Annotation(new Q
@@ -479,34 +479,16 @@
 otation(
-new QualifiedName(
 %22foo.bar
@@ -485,33 +485,32 @@
 n(%22foo.bar.Baz%22)
-)
 ;%0A        annota
@@ -707,37 +707,32 @@
 annotation = new
- Java
 Annotation(new Q
@@ -726,34 +726,16 @@
 otation(
-new QualifiedName(
 %22foo.bar
@@ -732,33 +732,32 @@
 n(%22foo.bar.Baz%22)
-)
 ;%0A        annota
@@ -965,21 +965,16 @@
 on = new
- Java
 Annotati
@@ -980,26 +980,8 @@
 ion(
-new QualifiedName(
 %22foo
@@ -986,25 +986,24 @@
 oo.bar.Baz%22)
-)
 ;%0A        an
@@ -1120,24 +1120,24 @@
 %22bar%22, 3);%0A%0A
-
         asse
@@ -1215,11 +1215,141 @@
 );%0A    %7D
+%0A%0A    private static JavaAnnotation newAnnotation(String name) %7B%0A        return new JavaAnnotation(new QualifiedName(name));%0A    %7D
 %0A%7D%0A

Remove duplication in test code