MCPcopy Create free account
hub / github.com/apache/groovy / testLoop

Method testLoop

src/test/groovy/org/codehaus/groovy/classgen/ForTest.java:69–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 }
68
69 @Test
70 void testLoop() throws Exception {
71 ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
72 classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
73
74 Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE.makeArray(), "coll")};
75
76 Statement loopStatement = createPrintlnStatement(new VariableExpression("i"));
77
78 ForStatement statement = new ForStatement(new Parameter(ClassHelper.OBJECT_TYPE, "i"), new VariableExpression("coll"), loopStatement);
79 classNode.addMethod(new MethodNode("iterateDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
80
81 Class<?> fooClass = loadClass(classNode);
82 assertTrue(fooClass != null, "Loaded a new class");
83
84 Object bean = fooClass.getDeclaredConstructor().newInstance();
85 assertTrue(bean != null, "Managed to create bean");
86
87 System.out.println("################ Now about to invoke a method with looping");
88 Object[] array = {Integer.valueOf(1234), "abc", "def"};
89
90 try {
91 InvokerHelper.invokeMethod(bean, "iterateDemo", new Object[]{array});
92 } catch (InvokerInvocationException e) {
93 System.out.println("Caught: " + e.getCause());
94 e.getCause().printStackTrace();
95 fail("Should not have thrown an exception");
96 }
97 System.out.println("################ Done");
98 }
99
100 @Test
101 void testManyParam() throws Exception {

Callers

nothing calls this directly

Calls 13

addConstructorMethod · 0.95
addMethodMethod · 0.95
invokeMethodMethod · 0.95
printStackTraceMethod · 0.80
makeArrayMethod · 0.65
newInstanceMethod · 0.65
loadClassMethod · 0.45
printlnMethod · 0.45
valueOfMethod · 0.45
getCauseMethod · 0.45

Tested by

no test coverage detected