/** * Tests whether the refactoring * * @throws Exception In case of an unexpected exception. */ @Test public void testRefactorCaseMethodAddDifferentParam() throws Exception { VariationPoint vp = RefactoringTestUtil.getMethodAddDifferentParamCase(VariabilityType.OPTXOR); IfStaticConfigClassMethod refactoring = new IfStaticConfigClassMethod(); refactoring.refactor(vp, null); // location has two methods Class vpLocation = (Class) ((JaMoPPJavaSoftwareElement) vp.getLocation()).getJamoppElement(); assertThat(vpLocation.getMethods().size(), equalTo(2)); Method firstMethod = vpLocation.getMethods().get(0); Method secondMethod = vpLocation.getMethods().get(1); // assert number of parameters assertThat(firstMethod.getParameters().size(), anyOf(equalTo(1), equalTo(2))); assertThat(secondMethod.getParameters().size(), anyOf(equalTo(1), equalTo(2))); assertThat( firstMethod.getParameters().size(), not(equalTo(secondMethod.getParameters().size()))); // assert method names and return types assertThat(firstMethod.getName(), equalTo("someMethod")); assertThat(secondMethod.getName(), equalTo("someMethod")); assertThat(firstMethod.getTypeReference(), instanceOf(Void.class)); assertThat(secondMethod.getTypeReference(), instanceOf(Void.class)); // verify correct VPM RefactoringTestUtil.assertValidVPM(vp); }
/** * Tests whether the canBeApplied method returns false for variation points that have variants * with implementing elements that are not supported by the refactoring. */ @Test public void testIfCanBeAppliedWithInvalidVariantElements() { Commentable location = ClassifiersFactory.eINSTANCE.createClass(); Commentable implEl1 = MembersFactory.eINSTANCE.createClassMethod(); Commentable implEl2 = MembersFactory.eINSTANCE.createConstructor(); VariationPoint vpMock = RefactoringTestUtil.getSimpleVPMock( VariabilityType.OPTXOR, Extensible.NO, BindingTime.COMPILE_TIME, location, implEl1, implEl2); IfStaticConfigClassMethod refactoring = new IfStaticConfigClassMethod(); assertThat(refactoring.canBeAppliedTo(vpMock).getSeverity(), is(Diagnostic.ERROR)); }
/** * Tests whether the refactoring * * @throws Exception In case of an unexpected exception. */ @Test public void testRefactorCaseMethodAddSameParam() throws Exception { VariationPoint vp = RefactoringTestUtil.getMethodAddSameParamCase(VariabilityType.OPTXOR); IfStaticConfigClassMethod refactoring = new IfStaticConfigClassMethod(); refactoring.refactor(vp, null); // location has one method Class vpLocation = (Class) ((JaMoPPJavaSoftwareElement) vp.getLocation()).getJamoppElement(); assertThat(vpLocation.getMethods().size(), equalTo(1)); // assert number of parameters assertThat(vpLocation.getMethods().get(0).getParameters().size(), equalTo(0)); // assert method name and return type assertThat(vpLocation.getMethods().get(0).getTypeReference(), instanceOf(Void.class)); // verify correct VPM RefactoringTestUtil.assertValidVPM(vp); }