Skip to content

Commit

Permalink
Switch to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 26, 2024
1 parent 0659cbb commit 2976f23
Show file tree
Hide file tree
Showing 312 changed files with 7,974 additions and 7,135 deletions.
40 changes: 13 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@
<spring.version>5.3.28</spring.version>
<!-- NOTE: upgrading jGit to 6.x requires Java 11 -->
<jgit.version>5.13.3.202401111512-r</jgit.version>
<junit.version>4.13.2</junit.version>
<bytebuddy.version>1.12.6</bytebuddy.version>
<testcontainers.version>1.16.2</testcontainers.version>
<testcontainers.version>1.19.7</testcontainers.version>
<grpc.version>1.27.2</grpc.version> <!-- Used only in tests -->
<!-- addresses multi transitive versions of jna under org.testcontainers:testcontainers:1.15.3 -->
<jna.version>5.8.0</jna.version>
Expand Down Expand Up @@ -554,16 +553,10 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.2.0</version>
<version>4.11.0</version>
</dependency>

<!-- Referenced indirectly by Bytebuddy -->
Expand Down Expand Up @@ -667,6 +660,16 @@
<artifactId>org.apache.servicemix.bundles.not-yet-commons-ssl</artifactId>
<version>0.3.11_1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.12.4</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -698,11 +701,6 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -934,6 +932,7 @@
<showPmdLog>false</showPmdLog>
<excludeRoots>
<excludeRoot>target/generated-sources/java</excludeRoot>
<excludeRoot>src/test/java</excludeRoot>
</excludeRoots>
<excludes>
<!-- Imported file that we want to preserve as-is -->
Expand Down Expand Up @@ -1338,24 +1337,11 @@
<rerunFailingTestsCount>${sshd.tests.rerun.count}</rerunFailingTestsCount>
</configuration>
<dependencies>
<!-- make sure using OUR version -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>

<!-- need to include it to ensure grouping detection -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${version.maven-surefire}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<distributionManagement>
<repository>
<id>dummy</id>
Expand Down
5 changes: 5 additions & 0 deletions sshd-checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<suppressions>
<suppress files="[\\/]*\.txt" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]*\.properties" checks="[a-zA-Z0-9]*"/>

<!-- Imported file that we want to keep as-is -->
<suppress files="[\\/]*BCrypt.java" checks="[a-zA-Z0-9]*"/>

<suppress files="[\\/]*test[\\/]*" checks="MethodCount"/>
<suppress files="[\\/]*test[\\/]*" checks="MissingCtor"/>

</suppressions>
11 changes: 8 additions & 3 deletions sshd-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
<artifactId>sshd-putty</artifactId>
<version>${project.version}</version>
</dependency>
<!-- For ed25519 support -->
<!-- For ed25519 support -->
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<optional>true</optional>
</dependency>

<!-- Test dependencies -->
<!-- Test dependencies -->
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
Expand All @@ -77,7 +77,7 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!-- For the I/O factories -->
<!-- For the I/O factories -->
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-mina</artifactId>
Expand All @@ -90,6 +90,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.mwiede</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,28 @@

import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
import org.apache.sshd.util.test.NoIoTestCase;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.Parameterized.UseParametersRunnerFactory;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

/**
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({ NoIoTestCase.class })
@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests
@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class)
@TestMethodOrder(MethodName.class)
@Tag("NoIoTestCase") // see https://github.com/junit-team/junit/wiki/Parameterized-tests
public class CliSupportSplitCommandLineArgumentsTest extends BaseTestSupport {
private final String line;
private final String[] expected;
private String line;
private String[] expected;

public CliSupportSplitCommandLineArgumentsTest(String line, String[] expected) {
public void initCliSupportSplitCommandLineArgumentsTest(String line, String[] expected) {
this.line = line;
this.expected = expected;
}

@Parameters(name = "{0}")
public static List<Object[]> parameters() {
return new ArrayList<Object[]>() {
// not serializing it
Expand Down Expand Up @@ -86,8 +80,10 @@ private void addTestCase(String line, String... expected) {
};
}

@Test
public void testSplitCommandLineArguments() {
@MethodSource("parameters")
@ParameterizedTest(name = "{0}")
public void splitCommandLineArguments(String line, String[] expected) {
initCliSupportSplitCommandLineArgumentsTest(line, expected);
String[] actual = CliSupport.splitCommandLineArguments(line);
assertArrayEquals(expected, actual);
}
Expand Down
14 changes: 12 additions & 2 deletions sshd-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,29 @@
<optional>true</optional>
</dependency>

<!-- For ed25519 support -->
<!-- For ed25519 support -->
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<optional>true</optional>
</dependency>

<!-- test dependencies -->
<!-- test dependencies -->
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.not-yet-commons-ssl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@
import java.util.List;

import org.apache.sshd.util.test.JUnitTestSupport;
import org.apache.sshd.util.test.NoIoTestCase;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({ NoIoTestCase.class })
@TestMethodOrder(MethodName.class)
@Tag("NoIoTestCase")
public class PasswordIdentityProviderTest extends JUnitTestSupport {
public PasswordIdentityProviderTest() {
super();
}

@Test
public void testMultiProvider() throws IOException, GeneralSecurityException {
void multiProvider() throws IOException, GeneralSecurityException {
String[][] values = {
{ getClass().getSimpleName(), getCurrentTestName() },
{ new Date(System.currentTimeMillis()).toString() },
Expand All @@ -69,7 +70,7 @@ public void testMultiProvider() throws IOException, GeneralSecurityException {

private static void assertProviderContents(String message, PasswordIdentityProvider p, Iterable<String> expected)
throws IOException, GeneralSecurityException {
assertNotNull(message + ": no provider", p);
assertNotNull(p, message + ": no provider");
assertEquals(message, expected, p.loadPasswords(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@

import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.util.test.JUnitTestSupport;
import org.apache.sshd.util.test.NoIoTestCase;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({ NoIoTestCase.class })
@TestMethodOrder(MethodName.class)
@Tag("NoIoTestCase")
public class ConfigFileHostEntryResolverTest extends JUnitTestSupport {
public ConfigFileHostEntryResolverTest() {
super();
}

@Test
public void testIdentityFilePaths() throws IOException {
void identityFilePaths() throws IOException {
final String config = "IdentityFile ~/.ssh/%r.key0\n" //
+ "Host foo\n" //
+ "IdentityFile ~/.ssh/%r.key1\n" //
Expand Down Expand Up @@ -84,7 +90,7 @@ public void testIdentityFilePaths() throws IOException {
}

@Test
public void testConfigFileReload() throws IOException {
void configFileReload() throws IOException {
Path dir = getTempTargetRelativeFile(getClass().getSimpleName());
AtomicInteger reloadCount = new AtomicInteger();
ConfigFileHostEntryResolver resolver = new ConfigFileHostEntryResolver(
Expand Down Expand Up @@ -159,22 +165,21 @@ private static void testConfigFileReload(
null);

if (entries == null) {
assertEquals(phase + "[" + index + "]: mismatched reload count", 0, reloadCount.get());
assertEquals(0, reloadCount.get(), phase + "[" + index + "]: mismatched reload count");
} else {
assertEquals(phase + "[" + index + "]: mismatched reload count", 1, reloadCount.get());
assertEquals(1, reloadCount.get(), phase + "[" + index + "]: mismatched reload count");
}

if (expected == null) {
assertNull(phase + "[" + index + "]: Unexpected success for " + query, actual);
assertNull(actual, phase + "[" + index + "]: Unexpected success for " + query);
} else {
assertNotNull(phase + "[" + index + "]: No result for " + query, actual);
assertNotSame(phase + "[" + index + "]: No cloned result for " + query, expected, actual);
assertEquals(phase + "[" + index + "]: Mismatched host for " + query,
expected.getHostName(), actual.getHostName());
assertEquals(phase + "[" + index + "]: Mismatched port for " + query,
expected.getPort(), actual.getPort());
assertEquals(phase + "[" + index + "]: Mismatched user for " + query,
expected.getUsername(), actual.getUsername());
assertNotNull(actual, phase + "[" + index + "]: No result for " + query);
assertNotSame(expected, actual, phase + "[" + index + "]: No cloned result for " + query);
assertEquals(expected.getHostName(), actual.getHostName(),
phase + "[" + index + "]: Mismatched host for " + query);
assertEquals(expected.getPort(), actual.getPort(), phase + "[" + index + "]: Mismatched port for " + query);
assertEquals(expected.getUsername(), actual.getUsername(),
phase + "[" + index + "]: Mismatched user for " + query);
}
}
}
Expand Down
Loading

0 comments on commit 2976f23

Please sign in to comment.