Skip to content

refactor(testing): migrate to SpoonAssertions and deprecate old assertion package#6741

Open
MartinWitt wants to merge 6 commits into
masterfrom
refactor/migrate-to-spoon-assertions
Open

refactor(testing): migrate to SpoonAssertions and deprecate old assertion package#6741
MartinWitt wants to merge 6 commits into
masterfrom
refactor/migrate-to-spoon-assertions

Conversation

@MartinWitt

@MartinWitt MartinWitt commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Removes the usage of old Assertions in our codebase and marks them for deprecation. Given we have the new ones we should only use them. Removing them is downstream breaking but tbf u shouldn't use them.

…tion package

Replaces all uses of spoon.testing.Assert with SpoonAssertions from
spoon.testing.assertions. Test model building is migrated to @modeltest,
JUnit assertions are replaced with AssertJ/SpoonAssertions. The eight
assertion classes in spoon.testing (src/main) are annotated
@deprecated(since="11", forRemoval=true) pointing to SpoonAssertions.
Copilot AI review requested due to automatic review settings May 31, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates test code away from the legacy spoon.testing.Assert fluent API toward the newer SpoonAssertions (from spoon.testing.assertions) and AssertJ. Test model construction is moved to the @ModelTest / @ByClass annotations, and assertThrows is replaced by assertThatThrownBy. The eight assertion classes that previously lived in src/main/java/spoon/testing are now marked @Deprecated(since = "11", forRemoval = true) and their Javadoc points to the replacement.

Changes:

  • Annotate the legacy spoon.testing.*Assert* classes as deprecated for removal.
  • Replace JUnit/spoon.testing.Assert usages in tests with SpoonAssertions + AssertJ, using @ModelTest/@ByClass for model setup.
  • Switch processor-driven assertions to call ProcessorUtils.process(...) directly and then compare resulting types.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/spoon/testing/Assert.java Adds @Deprecated(forRemoval=true) with pointer to SpoonAssertions.
src/main/java/spoon/testing/AbstractAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/AbstractCtElementAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/AbstractCtPackageAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/AbstractFileAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/CtElementAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/CtPackageAssert.java Deprecation annotation + Javadoc.
src/main/java/spoon/testing/FileAssert.java Deprecation annotation + Javadoc.
src/test/java/spoon/testing/AbstractAssertTest.java Migrates to @ModelTest + ProcessorUtils.process; the three processor-variant tests now contain identical bodies.
src/test/java/spoon/testing/CtElementAssertTest.java Migrates to @ModelTest/@ByClass and SpoonAssertions/AssertJ.
src/test/java/spoon/testing/CtPackageAssertTest.java Migrates to @ModelTest and SpoonAssertions/AssertJ.
src/test/java/spoon/testing/FileAssertTest.java Replaces file-path assertions with CtType-based comparisons via @ModelTest.
src/test/java/spoon/processing/ProcessingTest.java Migrates template-output test to @ModelTest + SpoonAssertions.
src/test/java/spoon/processing/CtGenerationTest.java Updates assertThat import to SpoonAssertions.
src/test/java/spoon/support/TypeAdaptorTest.java Updates assertThat import to SpoonAssertions.
src/test/java/spoon/test/pkg/PackageTest.java Updates assertThat import to SpoonAssertions.
src/test/java/spoon/test/fieldaccesses/FieldAccessTest.java Removes spoon.testing.Assert import and converts a CtElement-vs-String assertion to a raw toString() comparison.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 48 to 68
@ModelTest("./src/test/java/spoon/testing/testclasses/" + "Foo.java")
public void testTransformationWithProcessorClass(Factory actual) {
ProcessorUtils.process(actual, List.of(new FooToBarProcessor()));
List<CtType<?>> actualTypes = actual.Type().getAll();
List<CtType<?>> expectedTypes = build(new File("./src/test/java/spoon/testing/testclasses/" + "Bar.java")).Type().getAll();
Assertions.assertThat(actualTypes).hasSameSizeAs(expectedTypes);
for (int i = 0; i < actualTypes.size(); i++) {
assertThat(actualTypes.get(i)).isEqualTo(expectedTypes.get(i));
}
}

@Test
public void testTransformationWithProcessorName() {
assertThat(PATH + "Foo.java").withProcessor(FooToBarProcessor.class.getName()).isEqualTo(PATH + "Bar.java");
@ModelTest("./src/test/java/spoon/testing/testclasses/" + "Foo.java")
public void testTransformationWithProcessorName(Factory actual) {
ProcessorUtils.process(actual, List.of(new FooToBarProcessor()));
List<CtType<?>> actualTypes = actual.Type().getAll();
List<CtType<?>> expectedTypes = build(new File("./src/test/java/spoon/testing/testclasses/" + "Bar.java")).Type().getAll();
Assertions.assertThat(actualTypes).hasSameSizeAs(expectedTypes);
for (int i = 0; i < actualTypes.size(); i++) {
assertThat(actualTypes.get(i)).isEqualTo(expectedTypes.get(i));
}
}
assertEquals(1, elements.size());
assertTrue(elements.get(0).getType().getDeclaringType().isAnonymous());
assertThat(elements.get(0)).isEqualTo("private final Test test = new Test();");
assertEquals("private final Test test = new Test();", elements.get(0).toString());
@MartinWitt

Copy link
Copy Markdown
Collaborator Author

@I-Al-Istannen @SirYwell any comments?

@Test
public void testTransformationWithProcessorInstantiated() {
assertThat(PATH + "Foo.java").withProcessor(new FooToBarProcessor()).isEqualTo(PATH + "Bar.java");
@ModelTest("./src/test/java/spoon/testing/testclasses/" + "Foo.java")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not one string?

public void testTransformationWithProcessorInstantiated(Factory actual) {
ProcessorUtils.process(actual, List.of(new FooToBarProcessor()));
List<CtType<?>> actualTypes = actual.Type().getAll();
List<CtType<?>> expectedTypes = build(new File("./src/test/java/spoon/testing/testclasses/" + "Bar.java")).Type().getAll();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here

ProcessorUtils.process(actual, List.of(new FooToBarProcessor()));
List<CtType<?>> actualTypes = actual.Type().getAll();
List<CtType<?>> expectedTypes = build(new File("./src/test/java/spoon/testing/testclasses/" + "Bar.java")).Type().getAll();
Assertions.assertThat(actualTypes).hasSameSizeAs(expectedTypes);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can probably use the list assert here?

@I-Al-Istannen

Copy link
Copy Markdown
Collaborator

I think it also changes some test a bit but I like the idea :)

@MartinWitt

Copy link
Copy Markdown
Collaborator Author

@I-Al-Istannen fixed ur comments

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