NavigatorCodeGenerator { MethodSpec handleNoParamNoResultActivity(NavigableAnnotatedClass value) { TypeName activityTypeName = AndroidSpecificClassProvider.getActivityTypeName(); TypeName intentTypeName = AndroidSpecificClassProvider.getIntentTypeName(); String activityQualifiedName = value.getTypeElement().getQualifiedName().toString(); ArrayTypeName integerArray = ArrayTypeName.of(ClassName.get(Integer.class)); String annotatedClassName = CodeGeneratorHelper.buildMethodName(value.getAnnotatedClassName(), value.getNavigableAnnotation()); MethodSpec.Builder builder = MethodSpec.methodBuilder(annotatedClassName) .addParameter(activityTypeName, "activity", Modifier.FINAL) .addParameter(integerArray, "flags", Modifier.FINAL) .varargs() .addModifiers(Modifier.STATIC, Modifier.PUBLIC) .addStatement("$T intent = new $T(activity, " + activityQualifiedName + ".class)", intentTypeName, intentTypeName) .beginControlFlow("for (Integer flag : flags)") .addStatement("intent.addFlags(flag)") .endControlFlow() .addStatement("activity.startActivity(intent)"); return builder.build(); } NavigatorCodeGenerator(ProcessingEnvironment processingEnv); void generateClass(List<NavigableAnnotatedClass> navigableAnnotatedClassList);  }
@Test public void testHandleNoParamNoResultActivity() { String className = TestConstants.testPackageName + ".AA"; NavigableAnnotatedClass navigableAnnotatedClass = Mockito.mock(NavigableAnnotatedClass.class); TypeElement typeElement = Mockito.mock(TypeElement.class); Name name = Mockito.mock(Name.class); when(typeElement.getQualifiedName()).thenReturn(name); when(name.toString()).thenReturn(className); when(navigableAnnotatedClass.getTypeElement()).thenReturn(typeElement); when(navigableAnnotatedClass.getTypeElement().getQualifiedName()).thenReturn(name); when(navigableAnnotatedClass.getAnnotatedClassName()).thenReturn(className); MethodSpec methodSpec = navigatorCodeGenerator.handleNoParamNoResultActivity(navigableAnnotatedClass); TestUtils.testMethodSpec(methodSpec, className, TypeName.VOID, Modifier.PUBLIC, Modifier.STATIC); assertEquals(2, methodSpec.parameters.size()); TestUtils.testMethodParams(methodSpec.parameters.get(0), "activity", "android.app.Activity", Modifier.FINAL); TestUtils.testMethodParams(methodSpec.parameters.get(1), "flags", "java.lang.Integer[]", Modifier.FINAL); assertEquals(0, methodSpec.annotations.size()); }