EntanglingClass { @VisibleForTesting MethodSpec createUpdateMethod() { MethodSpec.Builder result = MethodSpec.methodBuilder("update") .addModifiers(PUBLIC) .addAnnotation(Override.class) .addParameter(ClassName.get("java.util", "Observable"), "observable") .addParameter(Object.class, "data"); result.addStatement("target.$L.setVisibility((((quantum.Tangle<Boolean>) observable).getValue()) " + "? android.view.View.GONE : android.view.View.VISIBLE)", fieldName); return result.build(); } EntanglingClass(String classPackage, String className, String targetClass, String fieldName, String connectionId);   }
@Test public void updateMethodShouldHaveCorrectName() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.name, is("update")); }
@Test public void updateMethodShouldBePublic() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.modifiers, hasItem(Modifier.PUBLIC)); }
@Test public void updateMethodShouldHaveOnlyOneModifier() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.modifiers, hasSize(1)); }
@Test public void updateMethodShouldHaveOverrideAnnotation() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.annotations, hasItem(AnnotationSpec.builder(Override.class).build())); }
@Test public void updateMethodShouldHaveOnlyOneAnnotation() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.annotations, hasSize(1)); }
@Test public void updateMethodShouldHaveObservableAndDataParams() { MethodSpec method = entanglingClass.createUpdateMethod(); ParameterSpec observableParam = ParameterSpec.builder( ClassName.get("java.util", "Observable"), "observable").build(); ParameterSpec dataParam = ParameterSpec.builder( Object.class, "data").build(); assertThat(method.parameters, hasItems(observableParam, dataParam)); }
@Test public void updateMethodShouldHaveOnlyTwoParams() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.parameters, hasSize(2)); }
@Test public void updateMethodShouldHaveVisibilityCode() { MethodSpec method = entanglingClass.createUpdateMethod(); assertThat(method.code.toString(), is(String.format( "target.%s.setVisibility((((quantum.Tangle<Boolean>) observable).getValue()) " + "? android.view.View.GONE : android.view.View.VISIBLE);\n", FIELD_NAME))); }