EntanglingClass { @VisibleForTesting MethodSpec createEntangleMethod() { MethodSpec.Builder result = MethodSpec.methodBuilder("entangle") .addModifiers(PUBLIC) .addParameter(TypeVariableName.get("T"), "target", FINAL); result.addStatement("this.target = target"); result.addStatement("quantum.Quantum.getTangle(id).addObserver(this)"); return result.build(); } EntanglingClass(String classPackage, String className, String targetClass, String fieldName, String connectionId);   }
@Test public void entangleMethodShouldHaveCorrectName() { MethodSpec entangle = entanglingClass.createEntangleMethod(); assertThat(entangle.name, is("entangle")); }
@Test public void entangleMethodShouldBePublic() { MethodSpec entangle = entanglingClass.createEntangleMethod(); assertThat(entangle.modifiers, hasItem(Modifier.PUBLIC)); }
@Test public void entangleMethodShouldHaveOnlyOneModifier() { MethodSpec entangle = entanglingClass.createEntangleMethod(); assertThat(entangle.modifiers, hasSize(1)); }
@Test public void entangleMethodShouldHaveTargetParameter() { MethodSpec entangle = entanglingClass.createEntangleMethod(); assertThat(entangle.parameters, hasItem(ParameterSpec.builder( TypeVariableName.get("T"), "target", FINAL).build())); }
@Test public void entangleMethodShouldHaveOnlyOneParameter() { MethodSpec entangle = entanglingClass.createEntangleMethod(); assertThat(entangle.parameters, hasSize(1)); }
@Test public void entangleMethodCodeShouldAddObserver() { MethodSpec method = entanglingClass.createEntangleMethod(); assertThat(method.code.toString(), is("this.target = target;\n" + "quantum.Quantum.getTangle(id).addObserver(this);\n")); }