()
| 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 { |
nothing calls this directly
no test coverage detected