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

[JBWS-4412] Migrate junit4 to junit5 #378

Merged
merged 5 commits into from
Mar 18, 2024
Merged

Conversation

gaol
Copy link
Contributor

@gaol gaol commented Mar 15, 2024

Issue: https://issues.redhat.com/browse/JBWS-4412

That this PRs try to do are:

  • Update all dependencies of junit:junit to org.junit.jupiter:junit-jupiter, update arquillian.version to 1.8.0.Final, update arquillian-wildfly-container.version to 5.1.0.Beta1
  • Replace junit4 methods with junit5 counterparts
  • Remove unnecessary class rules in junit4:
    • @EnableOnJDK, replace it with @EnabledOnJre
    • @IgnoreContainer, not used in the project
    • @IgnoreEnv, replace it with @DisabledIfSystemProperty
    • @IgnoreJdk, replace it with @DisabledIfSystemProperties
  • Replace the TestRule watcher in JBossWSTest to a static class callsed TestResultExtension, it will tries to call getClientJarPaths method defined by the test class using reflection.
  • Define some assertion methods in JBossWSTest for convenient.
  • Move tests that are using Deployer or ContainerController from @BeforeEach and @AfterEach methods to each @Test method because there is an issue in arquillian 1.8.0.Final which fails to deploy the deployments in the life cycle methods. Note that this is temporary workaround, it is highly recommended to switch back when the issue gets fixed.

@gaol gaol requested a review from a team as a code owner March 15, 2024 03:03
@gaol
Copy link
Contributor Author

gaol commented Mar 15, 2024

@jimma would you please review ? thanks

@jimma
Copy link
Member

jimma commented Mar 15, 2024

@gaol Thanks for the great contribution! This is really huge improvement to update to junit5, eliminate couple of old TestRules and get the tests more clean and organized. Just couple of minor things, please see my comments inlined.

@gaol gaol force-pushed the migrate-to-junit5 branch from c093c49 to 3f735aa Compare March 15, 2024 07:45
@gaol
Copy link
Contributor Author

gaol commented Mar 15, 2024

@jimma updated according to the feedback, please review again. :)

@@ -78,7 +77,6 @@ public static WebArchive createDeployment() {
return archive;
}

@Before
public void startContainerAndDeploy() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

add the same TODO as in the other test?

{
fail("Expected " + Arrays.asList(exp) + ", but was: null");
}
protected static void assertEquals(String message, String expected, String actual) {
Copy link
Member

Choose a reason for hiding this comment

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

I find these method wrappers very misleading. I know it could possibly mean to rewrite more places but now we use methods from two classes (JBossWSTest and Assertions) with same name but different parameters - would it be possible to go without those wrapper methods and just keep one (JUnit5) style in whole project?

protected static void assertTrue(String reason, boolean condition)
protected static void assertFalse(String reason, boolean condition)
protected static void assertEquals(String message, char expected, char actual)
protected static void assertEquals(String message, String expected, String actual) <-- especially this one is really ambiguous 
protected static void assertEquals(String message, Object expected, Object actual)
...etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the comment, I am good with removing these method wrappers. Yes, these were done for convenient to avoid rewriting assert methods in many places, but I get your point of misleading, will update it to use fully junit5 style only.

try {
cjpMethod = ctx.getRequiredTestClass().getDeclaredMethod("getClientJarPaths");
cjpMethod.setAccessible(true);
} catch (NoSuchMethodException nme) {
Copy link
Member

Choose a reason for hiding this comment

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

TestResultExtension is set for JBossWSTest and all descendants (which all will inherit getClientJarPaths() method) - so can this case ever happen? And even if it can, do we want to ignore it?

Also instead of using changing visibility via reflection, since we are only in test context, can't we simply make getClientJarPaths() method public to ease our lives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. Right, makes the getClientJarPaths() public and not catching the NoSuchMethodException would be better here.

@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
//https://issues.jboss.org/browse/JBEAP-5200
@DisabledIfSystemProperties({@DisabledIfSystemProperty(named = "java.vendor", matches = "IBM Corporation"),
Copy link
Member

Choose a reason for hiding this comment

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

I propose to simple remove this, we are running JDK11+ anyway so this rule is obsolete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, we are running JDK11+, will remove this line.

Copy link
Member

Choose a reason for hiding this comment

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

I think we'd better keep this. As we don't run IBM JDK 11 , this can probably gives use some hints that this isn't used to work with IBM JDK8, probably this still doesn't work with IBM JDK11 either.

@@ -74,15 +72,13 @@ public static WebArchive createDeployments() {
return archive;
}

@Before
Copy link
Member

Choose a reason for hiding this comment

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

again add TODO about arquiliian issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, will check it thoroughly. 👍

@gaol
Copy link
Contributor Author

gaol commented Mar 18, 2024

Updated according to the feedback.

@jimma jimma merged commit 01f2544 into jbossws:main Mar 18, 2024
13 checks passed
@jimma
Copy link
Member

jimma commented Mar 18, 2024

Thanks again for the great change @gaol and thanks for the review @jbliznak !

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