Remove now-invalid @Override when migrating TestCase subclasses - #1104
Merged
Conversation
`MigrateJUnitTestCase` only dropped `@Override` when it added a Jupiter lifecycle annotation, so `setUp()`/`tearDown()` that already carried `@Before`/`@After` kept an `@Override` that no longer compiles once `extends TestCase` is removed, as did `getName()` and `countTestCases()`. Now every method in a migrated `TestCase` subclass is checked against its remaining supertypes, skipping the `junit.framework` types that are going away, so `toString()`, interface implementations and overrides of an intermediate base that declares the method keep their annotation. Fixes #1103
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@Overrideon methods that overrodeTestCase, breaking compilation #1103MigrateJUnitTestCaseonly removed@Overrideas a side effect of adding a Jupiter lifecycle annotation. When aTestCasesubclass had already been half-migrated to JUnit 4 —setUp()carrying both@Overrideand@Before— that branch was skipped, soextends TestCasewas removed while the@Overridestayed behind and the class no longer compiled. Same forgetName()andcountTestCases(), which never hit that branch at all.Every method declaration in a migrated
TestCasesubclass is now checked against the supertypes it will still have after migration, skipping thejunit.frameworktypes that are going away.@Overrideis only removed when nothing else declares a matching method, so these keep it:toString(),equals(),hashCode()(declared onObject, and onTestCaseonly incidentally)RemoveAnnotationVisitorhandles the removal so the leftover blank line is cleaned up; the body is detached first so@Overrideon methods of anonymous classes inside is untouched.One existing expectation changed: in
convertExtendedTestCase,MathTest.setUp()overridesCTest.setUp(), whichCTestdeclares itself, so the@Overrideis now retained rather than stripped.