Skip to content

Commit

Permalink
test: Add test for Substitution.insertAllNestedTypes (#3998)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Larsén <[email protected]>
  • Loading branch information
Rohitesh-Kumar-Jain and slarse authored Jun 22, 2021
1 parent 17cc19d commit 075f91f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/java/spoon/test/template/SubstitutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,36 @@ private static class SingleFieldTemplate extends StatementTemplate {
@Override
public void statement() { }
}

@Test
public void testInsertAllNestedTypes() {
// 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());
assertEquals("nestedClass", targetType.getNestedType("nestedClass").getSimpleName());
}

private static class SinglyNestedTemplate extends StatementTemplate {

class nestedClass {
}

@Override
public void statement() {
}
}
}

0 comments on commit 075f91f

Please sign in to comment.