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

test: unite all tests for Substitution in one place #4016

Merged
merged 1 commit into from
Jun 29, 2021
Merged

test: unite all tests for Substitution in one place #4016

merged 1 commit into from
Jun 29, 2021

Conversation

Rohitesh-Kumar-Jain
Copy link
Contributor

As I created a new class SubstitutionTest and merged 4 new tests in it, I thought I should extract two existing tests so all tests can be together which were Specifically written for the Substitution class.

Now all tests related to this class are at the same place

link to #3967

@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain changed the title refactor: unite all tests specifically written for the Substitution class in the one place review: refactor: unite all tests specifically written for the Substitution class in the one place Jun 29, 2021
@monperrus monperrus changed the title review: refactor: unite all tests specifically written for the Substitution class in the one place test: unite all tests for Substitution in one place Jun 29, 2021
@monperrus monperrus merged commit 3e10fd5 into INRIA:master Jun 29, 2021
@monperrus
Copy link
Collaborator

Thanks @Rohitesh-Kumar-Jain

@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain deleted the extract-and-unite-all-substitution-tests branch June 29, 2021 16:08
Comment on lines -819 to -834
@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());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a direct test of Substitution.java, strictly speaking it should not have been moved. This is a higher-level test on a whole template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slarse I thought it is was probably meant for testing Substitution.insertAll(), but was testing Substitution.insertAllMethods() only. That was the use case of the test I got after going through it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method under test here is StatementTemplate.apply(). While that method in turn uses Substitution, it also uses a bunch of other classes and methods, so saying that this is a test of the Substitution class in isolation is a stretch of the imagination.

This is an end-to-end test of using a template, and so is perfectly suitable to be located in TemplateTest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I hurried to push the PR, I see that this extraction was wrong and unnecessary. I will be more sincere next time, it won't happen again, and I will fix this soon in the other PR which is already open for this class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to be sorry, I just noted that moving this seemed a bit off and made a note of it. A PR in Spoon is (at least) a two-person job, and both you and @monperrus missed this detail in this case. And that's OK, we can fix it later.

it won't happen again

It might happen again, and that's fine. We all make mistakes from time to time, especially when the "correct" solution isn't clear-cut (which with testing it rarely is).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
  NODES
COMMUNITY 2
Note 2
Project 3
USERS 1