refactor(testing): migrate to SpoonAssertions and deprecate old assertion package#6741
refactor(testing): migrate to SpoonAssertions and deprecate old assertion package#6741MartinWitt wants to merge 6 commits into
Conversation
…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.
There was a problem hiding this comment.
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.Assertusages in tests withSpoonAssertions+ AssertJ, using@ModelTest/@ByClassfor 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.
| @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()); |
|
@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") |
There was a problem hiding this comment.
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(); |
| 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); |
There was a problem hiding this comment.
We can probably use the list assert here?
|
I think it also changes some test a bit but I like the idea :) |
…bstractAssertTest
|
@I-Al-Istannen fixed ur comments |
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.