Skip to content

Commit

Permalink
Move Tests to Junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed May 18, 2023
1 parent 21c6f59 commit 3063137
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
27 changes: 8 additions & 19 deletions src/test/java/org/codehaus/mojo/tidy/task/PomTidyFixesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,22 @@
* under the License.
*/

import java.util.Objects;

import org.codehaus.plexus.util.IOUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(Parameterized.class)
public class PomTidyFixesTest {

protected static final String PATH = "fixes/order-and-indent-start-element-of-scope/";

@Parameters(name = "{0}")
public static Iterable<String> tests() {
return asList("property-ending-with-plugin.pom.xml", "property-ending-with-dependency.pom.xml");
}

@SuppressWarnings("checkstyle:VisibilityModifier")
@Parameter(0)
public String name;

@Test
public void shouldThrowNoError() throws Exception {
final String pom = IOUtil.toString(getClass().getResourceAsStream(PATH + name));
@ValueSource(strings = {"property-ending-with-plugin.pom.xml", "property-ending-with-dependency.pom.xml"})
@ParameterizedTest(name = "{0}")
void shouldThrowNoError(String name) throws Exception {
String pom = IOUtil.toString(Objects.requireNonNull(getClass().getResourceAsStream(PATH + name)));
String tidyPom = new PomTidy().tidy(pom);
assertEquals(pom, tidyPom, "nothing to tidy here");
}
Expand Down
40 changes: 16 additions & 24 deletions src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,22 @@
* under the License.
*/

import javax.xml.stream.XMLStreamException;

import java.io.IOException;
import java.io.InputStream;

import org.codehaus.plexus.util.IOUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(Parameterized.class)
public class PomTidyTest {
@Parameters(name = "{0}")
public static Iterable<String> tests() {
return asList(

@ParameterizedTest(name = "{0}")
@ValueSource(
strings = {
"add-xml-declaration",
"complete-pom",
"do-not-mix-tab-and-spaces",
Expand All @@ -49,22 +47,16 @@ public static Iterable<String> tests() {
"pom-with-line-without-indent",
"pom-with-profiles",
"pom-with-reporting",
"project-single-line");
}

@SuppressWarnings("checkstyle:VisibilityModifier")
@Parameter(0)
public String name;

@Test
public void generatesTidyPom() throws Exception {
String pom = readPom("pom.xml");
"project-single-line"
})
void generatesTidyPom(String name) throws IOException, XMLStreamException {
String pom = readPom(name, "pom.xml");
String tidyPom = new PomTidy().tidy(pom);
assertEquals(readPom("pom-expected.xml"), tidyPom);
assertEquals(readPom(name, "pom-expected.xml"), tidyPom);
}

private String readPom(String filename) throws IOException {
InputStream is = getClass().getResourceAsStream(name + "/" + filename);
private String readPom(String test, String filename) throws IOException {
InputStream is = getClass().getResourceAsStream(test + "/" + filename);
return IOUtil.toString(is);
}
}

0 comments on commit 3063137

Please sign in to comment.