NgTemplate extends AbstractJavaScriptComponent { public void addService(final String name, final Object callback) { Class<?> type = callback.getClass(); for (final Method method : type.getMethods()) { if (method.isAnnotationPresent(ServiceMethod.class)) { final String methodName = method.getName(); addFunction(name + "_" + methodName, new MethodInvoker( callback, method)); } } } NgTemplate(String templateSource, String moduleName);  NgTemplate(Package templatePackage, String moduleName);  NgTemplate(File templateFolder, String moduleName); @Override NgTemplateState getState(); void addService(final String name, final Object callback); void setUserState(String key, String value); void setUserState(String key, Object value);  }
@Test public void testAddService() { final Set<String> addedServices = new HashSet<>(); NgTemplate template = new NgTemplate("--", "NgTemplateTest") { private static final long serialVersionUID = 1L; protected void addFunction(String functionName, JavaScriptFunction function) { addedServices.add(functionName); } }; template.addService("testService", new Object() { @ServiceMethod public void test1() { } @ServiceMethod public void test2() { } @SuppressWarnings("unused") public void test3() { } @SuppressWarnings("unused") private void test4() { } }); assertEquals(2, addedServices.size()); assertTrue(addedServices.contains("testService_test1")); assertTrue(addedServices.contains("testService_test2")); assertFalse(addedServices.contains("testService_test3")); assertFalse(addedServices.contains("testService_test4")); }