Skip to content

Commit

Permalink
refactor: Revert incorrect move of test (#4029)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohitesh-Kumar-Jain authored Jul 6, 2021
1 parent 6cdcf2e commit 21dd0c8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
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_);
}
}

0 comments on commit 21dd0c8

Please sign in to comment.