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: test: add test for SubstituionInsertAllNestedTypes #3998

Merged
merged 4 commits into from
Jun 22, 2021
Merged
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions src/test/java/spoon/test/template/SubstitutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtType;
import spoon.reflect.factory.Factory;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.compiler.FileSystemFile;
import spoon.support.reflect.declaration.CtTypeImpl;
import spoon.template.StatementTemplate;
import spoon.template.Substitution;

import java.lang.annotation.Annotation;
import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -47,4 +51,44 @@ private static class SingleFieldTemplate extends StatementTemplate {
@Override
public void statement() { }
}

@Test
public void testSubstitutionInsertAllNestedTypes() {
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
// contract: Substitution.insertAllNestedTypes inserts the only nested class from a singly nested template into the target class

// arrange
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/SubstitutionTest.java"));

spoon.buildModel();
Factory factory = spoon.getFactory();

CtType<?> targetType = factory.Class().create("goodClass");
StatementTemplate template = new SinglyNestedTemplate();

// act
Substitution.insertAllNestedTypes(targetType, template);

// assert
assertEquals(1, targetType.getNestedTypes().size());
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
}

private static class SinglyNestedTemplate extends StatementTemplate {

public class nestedClass<T extends Annotation> extends CtTypeImpl<T> {

@Override
public boolean isSubtypeOf(CtTypeReference<?> type) {
return false;
}

@Override
public void accept(CtVisitor visitor) {
}
}
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

@Override
public void statement() {
}
}
}