Search in sources :

Example 1 with Pozole

use of spoon.test.annotation.testclasses.Pozole in project spoon by INRIA.

the class AnnotationLoopTest method testAnnotationDeclaredInForInit.

@Test
public void testAnnotationDeclaredInForInit() throws Exception {
    final CtType<Pozole> aPozole = ModelUtils.buildClass(Pozole.class);
    final CtFor aLoop = aPozole.getMethod("cook").getElements(new TypeFilter<>(CtFor.class)).get(0);
    assertEquals(3, aLoop.getForInit().size());
    assertEquals(SuppressWarnings.class, aLoop.getForInit().get(0).getAnnotations().get(0).getAnnotationType().getActualClass());
    assertEquals(SuppressWarnings.class, aLoop.getForInit().get(1).getAnnotations().get(0).getAnnotationType().getActualClass());
    assertEquals(SuppressWarnings.class, aLoop.getForInit().get(2).getAnnotations().get(0).getAnnotationType().getActualClass());
    assertEquals("u", ((CtLocalVariable) aLoop.getForInit().get(0)).getSimpleName());
    assertEquals("p", ((CtLocalVariable) aLoop.getForInit().get(1)).getSimpleName());
    assertEquals("e", ((CtLocalVariable) aLoop.getForInit().get(2)).getSimpleName());
    assertEquals(aPozole.getFactory().Type().STRING, ((CtLocalVariable) aLoop.getForInit().get(0)).getType());
    assertEquals(aPozole.getFactory().Type().STRING, ((CtLocalVariable) aLoop.getForInit().get(1)).getType());
    assertEquals(aPozole.getFactory().Type().STRING, ((CtLocalVariable) aLoop.getForInit().get(2)).getType());
    final String nl = System.lineSeparator();
    final String expected = "for (@java.lang.SuppressWarnings(\"rawtypes\")" + nl + "java.lang.String u = \"\", p = \"\", e = \"\"; u != e; u = p , p = \"\") {" + nl + "}";
    assertEquals(expected, aLoop.toString());
}
Also used : Pozole(spoon.test.annotation.testclasses.Pozole) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtFor(spoon.reflect.code.CtFor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CtFor (spoon.reflect.code.CtFor)1 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)1 Pozole (spoon.test.annotation.testclasses.Pozole)1