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

Migrate to JUnit 5. #1

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<version.org.wildfly>30.0.0.Final</version.org.wildfly>

<!-- Test dependencies -->
<version.junit.junit>4.13.2</version.junit.junit>
<version.org.junit>5.10.1</version.org.junit>
<version.org.jboss.shrinkwrap.shrinkwrap>1.2.6</version.org.jboss.shrinkwrap.shrinkwrap>

<!-- galleon properties -->
Expand Down Expand Up @@ -90,6 +90,18 @@
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${version.org.junit}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
Expand Down Expand Up @@ -119,15 +131,14 @@
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-launcher</artifactId>
<version>${version.org.wildfly.core}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit.junit}</version>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-launcher</artifactId>
<version>${version.org.wildfly.core}</version>
<scope>test</scope>
</dependency>

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package org.wildfly.plugin.tools;

import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand All @@ -16,14 +16,14 @@ public class DeploymentResultTestCase {

@Test
public void testSuccessful() {
Assert.assertTrue(DeploymentResult.SUCCESSFUL.successful());
Assert.assertNull(DeploymentResult.SUCCESSFUL.getFailureMessage());
Assert.assertFalse(DeploymentResult.SUCCESSFUL.asModelNode().isDefined());
Assertions.assertTrue(DeploymentResult.SUCCESSFUL.successful());
Assertions.assertNull(DeploymentResult.SUCCESSFUL.getFailureMessage());
Assertions.assertFalse(DeploymentResult.SUCCESSFUL.asModelNode().isDefined());

final DeploymentResult deploymentResult = new DeploymentResult(createCompositeOutcome());
Assert.assertTrue(deploymentResult.successful());
Assert.assertNull(deploymentResult.getFailureMessage());
Assert.assertTrue(deploymentResult.asModelNode().isDefined());
Assertions.assertTrue(deploymentResult.successful());
Assertions.assertNull(deploymentResult.getFailureMessage());
Assertions.assertTrue(deploymentResult.asModelNode().isDefined());
}

@Test
Expand All @@ -33,42 +33,42 @@ public void testFailed() {
"WFLYCTL0212: Duplicate resource [(\"deployment\" => \"foo.war\")]");

DeploymentResult deploymentResult = new DeploymentResult(failureModel);
Assert.assertFalse(deploymentResult.successful());
Assert.assertEquals("WFLYCTL0212: Duplicate resource [(\"deployment\" => \"foo.war\")]",
Assertions.assertFalse(deploymentResult.successful());
Assertions.assertEquals("WFLYCTL0212: Duplicate resource [(\"deployment\" => \"foo.war\")]",
deploymentResult.getFailureMessage());
Assert.assertTrue(deploymentResult.asModelNode().isDefined());
Assertions.assertTrue(deploymentResult.asModelNode().isDefined());

// Create a failure not based on model node
deploymentResult = new DeploymentResult("Test failed message");
Assert.assertFalse(deploymentResult.successful());
Assert.assertEquals("Test failed message", deploymentResult.getFailureMessage());
Assert.assertFalse(deploymentResult.asModelNode().isDefined());
Assertions.assertFalse(deploymentResult.successful());
Assertions.assertEquals("Test failed message", deploymentResult.getFailureMessage());
Assertions.assertFalse(deploymentResult.asModelNode().isDefined());

// Create a failure not based on model node
deploymentResult = new DeploymentResult("Test failed message %d", 2);
Assert.assertFalse(deploymentResult.successful());
Assert.assertEquals("Test failed message 2", deploymentResult.getFailureMessage());
Assert.assertFalse(deploymentResult.asModelNode().isDefined());
Assertions.assertFalse(deploymentResult.successful());
Assertions.assertEquals("Test failed message 2", deploymentResult.getFailureMessage());
Assertions.assertFalse(deploymentResult.asModelNode().isDefined());
}

@Test
public void testFailureAssertion() {
try {
new DeploymentResult("Test failure result").assertSuccess();
Assert.fail("Expected the deployment result to be a failure result");
Assertions.fail("Expected the deployment result to be a failure result");
} catch (DeploymentException ignore) {
}
try {
new DeploymentResult("Test failure result %d", 2).assertSuccess();
Assert.fail("Expected the deployment result to be a failure result");
Assertions.fail("Expected the deployment result to be a failure result");
} catch (DeploymentException ignore) {
}

// Create a failure description
try {
new DeploymentResult(createCompositeOutcome("WFLYCTL0212: Duplicate resource [(\"deployment\" => \"foo.war\")]"))
.assertSuccess();
Assert.fail("Expected the deployment result to be a failure result");
Assertions.fail("Expected the deployment result to be a failure result");
} catch (DeploymentException ignore) {
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/wildfly/plugin/tools/DeploymentTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.wildfly.plugin.tools.common.Simple;

/**
Expand All @@ -30,16 +30,16 @@ public class DeploymentTestCase {
@Test
public void testPathDeploymentName() {
final Deployment deployment = Deployment.of(TEST_DEPLOYMENT_DIR);
Assert.assertEquals(TEST_DEPLOYMENT_FILE_NAME, deployment.getName());
Assertions.assertEquals(TEST_DEPLOYMENT_FILE_NAME, deployment.getName());

// Set the file name and expect the new name
final String name = "changed.war";
deployment.setName(name);
Assert.assertEquals(name, deployment.getName());
Assertions.assertEquals(name, deployment.getName());

// Reset the name to null and expect the file name
deployment.setName(null);
Assert.assertEquals(TEST_DEPLOYMENT_FILE_NAME, deployment.getName());
Assertions.assertEquals(TEST_DEPLOYMENT_FILE_NAME, deployment.getName());
}

@Test
Expand All @@ -49,18 +49,18 @@ public void testInputStreamDeploymentName() {
.addClass(Simple.class);
final TestInputStream in = new TestInputStream(war);
final Deployment deployment = Deployment.of(in, name);
Assert.assertEquals(name, deployment.getName());
Assert.assertTrue("Expected to the input stream to be closed", in.closed.get());
Assertions.assertEquals(name, deployment.getName());
Assertions.assertTrue(in.closed.get(), "Expected to the input stream to be closed");

// Set the file name and expect the new name
final String changedName = "changed.war";
deployment.setName(changedName);
Assert.assertEquals(changedName, deployment.getName());
Assertions.assertEquals(changedName, deployment.getName());

// Reset the name to null and expect a failure
try {
deployment.setName(null);
Assert.fail("Expected setting the name to null for an input stream to fail.");
Assertions.fail("Expected setting the name to null for an input stream to fail.");
} catch (IllegalArgumentException ignore) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.client.helpers.domain.DomainClient;
import org.jboss.dmr.ModelNode;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.wildfly.core.launcher.DomainCommandBuilder;
import org.wildfly.core.launcher.Launcher;
import org.wildfly.core.launcher.ProcessHelper;
Expand Down Expand Up @@ -59,13 +59,13 @@ public class DomainDeploymentManagerIT extends AbstractDeploymentManagerTest {
private static DomainClient client;
private static Thread consoleConsomer;

@BeforeClass
@BeforeAll
public static void startServer() throws Exception {
boolean ok = false;
try {
client = DomainClient.Factory.create(Environment.createClient());
if (ServerHelper.isDomainRunning(client) || ServerHelper.isStandaloneRunning(client)) {
Assert.fail("A WildFly server is already running: " + ServerHelper.getContainerDescription(client));
Assertions.fail("A WildFly server is already running: " + ServerHelper.getContainerDescription(client));
}
final DomainCommandBuilder commandBuilder = DomainCommandBuilder.of(Environment.WILDFLY_HOME);
if (IS_MODULAR_JDK) {
Expand All @@ -90,7 +90,7 @@ public static void startServer() throws Exception {
}
}

@AfterClass
@AfterAll
@SuppressWarnings("StaticVariableUsedBeforeInitialization")
public static void shutdown() throws Exception {
try {
Expand Down Expand Up @@ -171,10 +171,10 @@ public void testFailedUndeploy() throws Exception {

@Test
public void testDeploymentQueries() throws Exception {
Assert.assertTrue("No deployments should exist.", deploymentManager.getDeployments().isEmpty());
Assert.assertTrue("No deployments should exist.", deploymentManager.getDeploymentNames().isEmpty());
Assert.assertTrue(String.format("No deployments should exist on %s", DEFAULT_SERVER_GROUP),
deploymentManager.getDeployments(DEFAULT_SERVER_GROUP).isEmpty());
Assertions.assertTrue(deploymentManager.getDeployments().isEmpty(), "No deployments should exist.");
Assertions.assertTrue(deploymentManager.getDeploymentNames().isEmpty(), "No deployments should exist.");
Assertions.assertTrue(deploymentManager.getDeployments(DEFAULT_SERVER_GROUP).isEmpty(), () ->
String.format("No deployments should exist on %s", DEFAULT_SERVER_GROUP));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.dmr.ModelNode;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.wildfly.core.launcher.Launcher;
import org.wildfly.core.launcher.ProcessHelper;
import org.wildfly.core.launcher.StandaloneCommandBuilder;
Expand All @@ -28,13 +28,13 @@ public class StandaloneDeploymentManagerIT extends AbstractDeploymentManagerTest
private static ModelControllerClient client;
private static Thread consoleConsomer;

@BeforeClass
@BeforeAll
public static void startServer() throws Exception {
boolean ok = false;
try {
client = Environment.createClient();
if (ServerHelper.isDomainRunning(client) || ServerHelper.isStandaloneRunning(client)) {
Assert.fail("A WildFly server is already running: " + ServerHelper.getContainerDescription(client));
Assertions.fail("A WildFly server is already running: " + ServerHelper.getContainerDescription(client));
}
final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(Environment.WILDFLY_HOME);
process = Launcher.of(commandBuilder).launch();
Expand All @@ -56,7 +56,7 @@ public static void startServer() throws Exception {
}
}

@AfterClass
@AfterAll
@SuppressWarnings("StaticVariableUsedBeforeInitialization")
public static void shutdown() throws Exception {
try {
Expand All @@ -74,11 +74,11 @@ public static void shutdown() throws Exception {

@Test
public void testDeploymentQueries() throws Exception {
Assert.assertTrue("No deployments should exist.", deploymentManager.getDeployments().isEmpty());
Assert.assertTrue("No deployments should exist.", deploymentManager.getDeploymentNames().isEmpty());
Assertions.assertTrue(deploymentManager.getDeployments().isEmpty(), "No deployments should exist.");
Assertions.assertTrue(deploymentManager.getDeploymentNames().isEmpty(), "No deployments should exist.");
try {
deploymentManager.getDeployments("main-server-group");
Assert.fail("This is not a domain server and DeploymentManager.getDeployments(serverGroup) should have failed.");
Assertions.fail("This is not a domain server and DeploymentManager.getDeployments(serverGroup) should have failed.");
} catch (IllegalStateException ignore) {
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/wildfly/plugin/tools/VersionTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.SortedSet;
import java.util.TreeSet;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand All @@ -22,9 +22,9 @@ public class VersionTestCase {

@Test
public void checkCompare() {
Assert.assertEquals(-1, VersionComparator.compareVersion("1.0.0.Final", "1.0.1.Final"));
Assert.assertEquals(0, VersionComparator.compareVersion("1.0.1.Final", "1.0.1.Final"));
Assert.assertEquals(1, VersionComparator.compareVersion("1.0.2.Final", "1.0.1.Final"));
Assertions.assertEquals(-1, VersionComparator.compareVersion("1.0.0.Final", "1.0.1.Final"));
Assertions.assertEquals(0, VersionComparator.compareVersion("1.0.1.Final", "1.0.1.Final"));
Assertions.assertEquals(1, VersionComparator.compareVersion("1.0.2.Final", "1.0.1.Final"));
}

@Test
Expand Down Expand Up @@ -61,14 +61,14 @@ public void testSortOrder() {
Collections.shuffle(versions);

// All entries should in the same order
Assert.assertTrue(orderedVersions.containsAll(versions));
Assertions.assertTrue(orderedVersions.containsAll(versions));
versions.sort(new VersionComparator());
Assert.assertEquals(orderedVersions, versions);
Assertions.assertEquals(orderedVersions, versions);
}

private void compareLatest(final String expected, final String... versions) {
final SortedSet<String> set = new TreeSet<>(new VersionComparator());
set.addAll(Arrays.asList(versions));
Assert.assertEquals(expected, set.last());
Assertions.assertEquals(expected, set.last());
}
}
Loading