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 tests to modern JUnit Jupiter #51

Merged
merged 1 commit into from
Oct 1, 2021
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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -163,8 +163,8 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/net/revelc/code/impsort/ImpSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

package net.revelc.code.impsort;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
Expand All @@ -35,7 +35,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

import com.github.javaparser.ParserConfiguration.LanguageLevel;
import com.github.javaparser.ast.PackageDeclaration;
Expand Down
30 changes: 14 additions & 16 deletions src/test/java/net/revelc/code/impsort/LineEndingEdgeCasesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
package net.revelc.code.impsort;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import net.revelc.code.impsort.ex.ImpSortException;
import net.revelc.code.impsort.ex.ImpSortException.Reason;
Expand All @@ -40,16 +39,15 @@ public class LineEndingEdgeCasesTest {
private static Grouper eclipseDefaults =
new Grouper("java.,javax.,org.,com.", "", false, false, true);

@Rule
public TemporaryFolder folder =
new TemporaryFolder(new File(System.getProperty("user.dir"), "target"));
@TempDir
public File folder;
ctubbsii marked this conversation as resolved.
Show resolved Hide resolved

/**
* Test successfully parsing empty file (zero bytes).
*/
@Test
public void testEmptyFile() throws IOException {
Path p = folder.newFile("EmptyFile.java").toPath();
Path p = new File(folder, "EmptyFile.java").toPath();
Files.write(p, new byte[0]);
Result actual = new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.AUTO).parseFile(p);
assertEquals(Result.EMPTY_FILE, actual);
Expand All @@ -64,7 +62,7 @@ public void testEmptyFile() throws IOException {
public void testFileKeepWithoutLineEnding() throws IOException {
String s =
"import java.lang.System;public class FileWithoutNewline{public static void main(String[] args){System.out.println(\"Hello, world!\");}}";
Path p = folder.newFile("FileWithoutLineEnding.java").toPath();
Path p = new File(folder, "FileWithoutLineEnding.java").toPath();
Files.write(p, s.getBytes(UTF_8));
ImpSortException e = assertThrows(ImpSortException.class,
() -> new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.KEEP).parseFile(p));
Expand All @@ -79,7 +77,7 @@ public void testFileKeepWithoutLineEnding() throws IOException {
public void testFileAutoWithoutLineEnding() throws IOException {
String s =
"import java.lang.System;public class FileWithoutNewline{public static void main(String[] args){System.out.println(\"Hello, world!\");}}";
Path p = folder.newFile("FileWithoutLineEnding.java").toPath();
Path p = new File(folder, "FileWithoutLineEnding.java").toPath();
Files.write(p, s.getBytes(UTF_8));
Result result = new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.AUTO).parseFile(p);
assertEquals(1, result.getImports().size());
Expand All @@ -97,7 +95,7 @@ public void testFileAutoWithoutLineEnding() throws IOException {
public void testPartiallyParsedFile() throws IOException {
String s = "public class InvalidFile {\n" + " public static void main(String[] args) {\n"
+ " System.out.println(\"Hello, world!\")\n" + " }\n" + "}\n";
Path p = folder.newFile("InvalidFile.java").toPath();
Path p = new File(folder, "InvalidFile.java").toPath();
Files.write(p, s.getBytes(UTF_8));
ImpSortException e = assertThrows(ImpSortException.class,
() -> new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.AUTO).parseFile(p));
Expand All @@ -111,7 +109,7 @@ public void testPartiallyParsedFile() throws IOException {
@Test
public void testInvalidFile() throws IOException {
String s = "\0\n\n";
Path p = folder.newFile("NoResult.java").toPath();
Path p = new File(folder, "NoResult.java").toPath();
Files.write(p, s.getBytes(UTF_8));
ImpSortException e = assertThrows(ImpSortException.class,
() -> new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.AUTO).parseFile(p));
Expand All @@ -125,7 +123,7 @@ public void testInvalidFile() throws IOException {
*/
@Test
public void testMissingFile() throws IOException {
Path p = new File(folder.getRoot().getAbsolutePath(), "MissingFile.java").toPath();
Path p = new File(folder.getAbsolutePath(), "MissingFile.java").toPath();
NoSuchFileException e = assertThrows(NoSuchFileException.class,
() -> new ImpSort(UTF_8, eclipseDefaults, true, true, LineEnding.AUTO).parseFile(p));
assertEquals(p.toString(), e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/revelc/code/impsort/LineEndingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
package net.revelc.code.impsort;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

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

/**
* Test class for {@link LineEnding}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package net.revelc.code.impsort.maven.plugin;

import static net.revelc.code.impsort.maven.plugin.AbstractImpSortMojo.getLanguageLevel;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

import com.github.javaparser.ParserConfiguration.LanguageLevel;

Expand Down