Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: refactor: refactor-the-wrongly-extracted-test #4029

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/test/java/spoon/test/template/SubstitutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,35 +180,6 @@ public void testCreateTypeFromTemplate() {
assertEquals("BETTER", genEnum.getEnumValues().get(1).getSimpleName());
}

@Test
public void testInsertAllMethods() {
Factory factory = createFactoryWithTemplates();

CtClass<?> testSimpleTpl = factory.Class().create("TestSimpleTpl");
//whitespace seems wrong here
new SimpleTemplate().apply(testSimpleTpl);

Set<CtMethod<?>> listMethods = testSimpleTpl.getMethods();
assertEquals(0, testSimpleTpl.getMethodsByName("apply").size());
assertEquals(1, listMethods.size());
}

/**
* Created by urli on 31/05/2017.
*/
private static class SimpleTemplate extends StatementTemplate {

@Override
public CtClass apply(CtType targetType) {
Substitution.insertAll(targetType, this);

return (CtClass) targetType;
}

@Override
public void statement() { }
}

@Test
public void testSubstituteMethodBodyWithTemplatedInitializer() {
// contract: Given a block with a templated initializer, substituteMethodBody should return a
Expand Down
34 changes: 18 additions & 16 deletions src/test/java/spoon/test/template/TemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,7 @@
import spoon.support.compiler.FileSystemFile;
import spoon.support.template.Parameters;
import spoon.template.*;
import spoon.test.template.testclasses.AnExpressionTemplate;
import spoon.test.template.testclasses.AnotherFieldAccessTemplate;
import spoon.test.template.testclasses.ArrayAccessTemplate;
import spoon.test.template.testclasses.FieldAccessOfInnerClassTemplate;
import spoon.test.template.testclasses.FieldAccessTemplate;
import spoon.test.template.testclasses.Flow;
import spoon.test.template.testclasses.FlowMatcher;
import spoon.test.template.testclasses.InnerClassTemplate;
import spoon.test.template.testclasses.InvocationTemplate;
import spoon.test.template.testclasses.NtonCodeTemplate;
import spoon.test.template.testclasses.ObjectIsNotParamTemplate;
import spoon.test.template.testclasses.SecurityCheckerTemplate;
import spoon.test.template.testclasses.SubStringTemplate;
import spoon.test.template.testclasses.SubstituteLiteralTemplate;
import spoon.test.template.testclasses.SubstituteRootTemplate;
import spoon.test.template.testclasses.TypeReferenceClassAccessTemplate;
import spoon.test.template.testclasses.*;
import spoon.test.template.testclasses.bounds.CheckBound;
import spoon.test.template.testclasses.bounds.CheckBoundMatcher;
import spoon.test.template.testclasses.bounds.CheckBoundTemplate;
Expand Down Expand Up @@ -712,6 +697,23 @@ public void testTemplateInterfaces() throws Exception {
assertTrue(superc.getSuperInterfaces().contains(factory.Type().createReference(Remote.class)));
}

@Test
public void testSimpleTemplate() {
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SimpleTemplate.java"));
spoon.buildModel();

Factory factory = spoon.getFactory();

CtClass<?> testSimpleTpl = factory.Class().create("TestSimpleTpl");
//whitespace seems wrong here
new SimpleTemplate("HelloWorld").apply(testSimpleTpl);

Set<CtMethod<?>> listMethods = testSimpleTpl.getMethods();
assertEquals(0, testSimpleTpl.getMethodsByName("apply").size());
assertEquals(1, listMethods.size());
}

@Test
public void testTemplateMatcherWithWholePackage() {
Launcher spoon = new Launcher();
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/spoon/test/template/testclasses/SimpleTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package spoon.test.template.testclasses;

import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtType;
import spoon.template.Local;
import spoon.template.Parameter;
import spoon.template.StatementTemplate;
import spoon.template.Substitution;
import spoon.template.Template;

import java.sql.Statement;

/**
* Created by urli on 31/05/2017.
*/
public class SimpleTemplate extends StatementTemplate {
// template parameter fields
@Parameter
String _parameter_;

// parameters binding
@Local
public SimpleTemplate(String parameter) {
_parameter_ = parameter;
}

@Override
public CtClass apply(CtType targetType) {
Substitution.insertAll(targetType, this);

return (CtClass) targetType;
}

@Override
public void statement() throws Throwable {
System.out.println(_parameter_);
}
}