Migrate tests to JUnit5#509
Conversation
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
b9f2b99 to
e53c08b
Compare
|
@jenkinsci/branch-api-plugin-developers Kindly requesting a review. |
# Conflicts: # src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java
# Conflicts: # src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java
jglick
left a comment
There was a problem hiding this comment.
-0 I guess, given the degraded assertions in a couple places.
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> |
| assumeThat("We have no master branch", master, nullValue()); | ||
| assumeTrue(master == null, "We have no master branch"); |
There was a problem hiding this comment.
What is the purpose of this sort of change? It seems like a regression in the quality of test assertions: before, you would get the actual value of master if it existed.
There was a problem hiding this comment.
There does not seem to be an equivalent in the latest JUnit / Hamcrest. I don't recall the history but I think it got dropped by both libraries in a major version and was not picked up again. There was a issue about it on their GitHub but I can't seem to find it right now.
There was a problem hiding this comment.
Oh I see, this was assume not assert. I think it should have been assert. There is no apparent reason why this would be sensitive to the test environment.
There was a problem hiding this comment.
Mistake in #104 I think. given_multibranchWithMergeableChangeRequests_when_reindexing_then_mergableChangeRequestsRebuilt passes, it is not skipped.
| assumeThat("The head change request was built", crHead.getLastBuild(), notNullValue()); | ||
| assumeThat("The head change request was built", crHead.getLastBuild().getNumber(), is(1)); | ||
| assumeTrue(crMerge.getLastBuild() != null, "The merge change request was built"); | ||
| assumeTrue(crMerge.getLastBuild().getNumber() == 1, "The merge change request was built"); |
There was a problem hiding this comment.
Similarly, here you would have gotten a number other than 1. Now you will just get a failure.
| assertDataMigrated(foo); | ||
| void createdFromScratch() throws Throwable { | ||
| story.then(j -> { | ||
| OrganizationFolder foo = j.createProject(OrganizationFolder.class, "foo"); |
| c.addFile("foo", "feature", "add new feature", "FEATURE", "new".getBytes()); | ||
| String configXml = IOUtils.toString(getClass().getResourceAsStream("UpdatingFromXmlTest/config.xml"), StandardCharsets.UTF_8).replace("fixme", c.getId()); | ||
| BasicMultiBranchProject prj = (BasicMultiBranchProject) r.jenkins.createProjectFromXML("foo", new ReaderInputStream(new StringReader(configXml), StandardCharsets.UTF_8)); | ||
| BasicMultiBranchProject prj = (BasicMultiBranchProject) r.jenkins.createProjectFromXML("foo", ReaderInputStream.builder().setReader(new StringReader(configXml)).setCharset(StandardCharsets.UTF_8).get()); |
There was a problem hiding this comment.
What does this have to do with JUnit 5? If you want to propose random code improvements, great, but please file them separately.
| instance.jobDecorator((Class) Job.class).project(job); | ||
| assertTrue("The IOException was caught and ignored", true); | ||
| assertDoesNotThrow(() -> instance.jobDecorator((Class) Job.class).project(job)); |
There was a problem hiding this comment.
Or just delete the assertTrue; assertDoesNotThrow seems useless.
There was a problem hiding this comment.
I'd usually agree since I oftentimes don't see a reason to use assertDoesNotThrow. In this instance however I feel it makes the intention clearer and gives the call to #project a purpose. It's more elegant than using assertTrue(true). Removing assertions should not be my goal here.
This PR aims to migrate all tests to JUnit5. Changes include:
I am well aware that this is a quite large changeset however I hope that there is still interest in this PR and it will be reviewed.
If there are any questions, please do not hesitate to ping me.