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

Restore test runs, add jacoco, and fix resulting broken tests #326

Merged
merged 8 commits into from
Mar 27, 2022
4 changes: 4 additions & 0 deletions license-maven-plugin-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
</site>
</distributionManagement>

<properties>
<jacoco.minimum.coverage>0.80</jacoco.minimum.coverage>
</properties>

<dependencies>
<dependency>
<groupId>com.mycila</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
Expand Down Expand Up @@ -64,18 +63,17 @@ private void assertAuthor(CopyrightAuthorProvider provider, String path, String
}

private static Document newDocument(String relativePath) {
Path path = Paths.get(gitRepoRoot.toAbsolutePath() + File.separator
Path path = Paths.get(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar));
return new Document(path.toFile(), null, "utf-8", new String[0], null);
}

@BeforeAll
static void beforeClass() throws IOException {
URL url = GitLookupTest.class.getResource("git-test-repo.zip");
Path unzipDestination = tempFolder.toPath();
gitRepoRoot = Files.createDirectory(unzipDestination);
gitRepoRoot = Paths.get(tempFolder.toPath() + File.separator + "git-test-repo");

GitLookupTest.unzip(url, unzipDestination);
GitLookupTest.unzip(url, tempFolder.toPath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
Expand All @@ -36,15 +35,15 @@
/**
* @author <a href="mailto:[email protected]">Peter Palaga</a>
*/
public class CopyrightRangeProviderTest {
class CopyrightRangeProviderTest {

private static Path gitRepoRoot;

@TempDir
static File tempFolder;

@Test
public void copyrightRange() {
void copyrightRange() {
CopyrightRangeProvider provider = new CopyrightRangeProvider();

assertRange(provider, "dir1/file1.txt", "2000", "2006", "1999-2006", "2000-2006");
Expand Down Expand Up @@ -84,18 +83,17 @@ private void assertRange(CopyrightRangeProvider provider, String path, String in
}

private static Document newDocument(String relativePath) {
Path path = Paths.get(gitRepoRoot.toAbsolutePath() + File.separator
Path path = Paths.get(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar));
return new Document(path.toFile(), null, "utf-8", new String[0], null);
}

@BeforeAll
public static void beforeClass() throws IOException {
static void beforeClass() throws IOException {
URL url = GitLookupTest.class.getResource("git-test-repo.zip");
Path unzipDestination = tempFolder.toPath();
gitRepoRoot = Files.createDirectory(unzipDestination);
gitRepoRoot = Paths.get(tempFolder.toPath() + File.separator + "git-test-repo");

GitLookupTest.unzip(url, unzipDestination);
GitLookupTest.unzip(url, tempFolder.toPath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Calendar;
Expand All @@ -40,20 +39,18 @@
/**
* @author <a href="mailto:[email protected]">Peter Palaga</a>
*/
public class GitLookupTest {
class GitLookupTest {

private static Path gitRepoRoot;

@TempDir
static File tempFolder;

@BeforeAll
public static void beforeClass() throws IOException {
static void beforeClass() throws IOException {
URL url = GitLookupTest.class.getResource("git-test-repo.zip");
Path unzipDestination = tempFolder.toPath();
gitRepoRoot = Files.createDirectory(unzipDestination);

unzip(url, unzipDestination);
gitRepoRoot = Paths.get(tempFolder.toPath() + File.separator + "git-test-repo");
unzip(url, tempFolder.toPath());
}

static void unzip(URL url, Path unzipDestination) throws IOException {
Expand Down Expand Up @@ -92,7 +89,7 @@ static void unzip(URL url, Path unzipDestination) throws IOException {
}

@Test
public void modified() throws GitAPIException, IOException {
void modified() throws GitAPIException, IOException {
assertLastChange(newAuthorLookup(), "dir1/file1.txt", 2006);
assertLastChange(newCommitterLookup(), "dir1/file1.txt", 2006);

Expand All @@ -101,7 +98,7 @@ public void modified() throws GitAPIException, IOException {
}

@Test
public void justCreated() throws GitAPIException, IOException {
void justCreated() throws GitAPIException, IOException {
assertLastChange(newAuthorLookup(), "dir2/file2.txt", 2007);
assertLastChange(newCommitterLookup(), "dir2/file2.txt", 2007);

Expand All @@ -110,7 +107,7 @@ public void justCreated() throws GitAPIException, IOException {
}

@Test
public void moved() throws GitAPIException, IOException {
void moved() throws GitAPIException, IOException {
assertLastChange(newAuthorLookup(), "dir1/file3.txt", 2009);
assertLastChange(newCommitterLookup(), "dir1/file3.txt", 2010);

Expand All @@ -120,7 +117,7 @@ public void moved() throws GitAPIException, IOException {
}

@Test
public void newUnstaged() throws GitAPIException, IOException {
void newUnstaged() throws GitAPIException, IOException {
int currentYear = getCurrentGmtYear();
assertLastChange(newAuthorLookup(), "dir1/file5.txt", currentYear);
assertLastChange(newCommitterLookup(), "dir1/file5.txt", currentYear);
Expand All @@ -130,7 +127,7 @@ public void newUnstaged() throws GitAPIException, IOException {
}

@Test
public void newStaged() throws GitAPIException, IOException {
void newStaged() throws GitAPIException, IOException {
int currentYear = getCurrentGmtYear();
assertLastChange(newAuthorLookup(), "dir1/file6.txt", currentYear);
assertLastChange(newCommitterLookup(), "dir1/file6.txt", currentYear);
Expand All @@ -149,15 +146,15 @@ private int getCurrentGmtYear() {
}

@Test
public void reuseProvider() throws GitAPIException, IOException {
void reuseProvider() throws GitAPIException, IOException {
GitLookup provider = newAuthorLookup();
assertLastChange(provider, "dir1/file1.txt", 2006);
assertLastChange(provider, "dir2/file2.txt", 2007);
assertLastChange(provider, "dir1/file3.txt", 2009);
}

@Test
public void timezone() throws GitAPIException, IOException {
void timezone() throws GitAPIException, IOException {
try {
new GitLookup(gitRepoRoot.toFile(), DateSource.AUTHOR, TimeZone.getTimeZone("GMT"), 10);
Assertions.fail("RuntimeException expected");
Expand Down Expand Up @@ -196,14 +193,14 @@ private GitLookup newCommitterLookup() throws IOException {

private void assertLastChange(GitLookup provider, String relativePath, int expected) throws
GitAPIException, IOException {
int actual = provider.getYearOfLastChange(Paths.get(gitRepoRoot.toAbsolutePath() + File.separator
int actual = provider.getYearOfLastChange(Paths.get(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar)).toFile());
Assertions.assertEquals(expected, actual);
}

private void assertCreation(GitLookup provider, String relativePath, int expected) throws
GitAPIException, IOException {
int actual = provider.getYearOfCreation(Paths.get(gitRepoRoot.toAbsolutePath() + File.separator
int actual = provider.getYearOfCreation(Paths.get(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar)).toFile());
Assertions.assertEquals(expected, actual);
}
Expand Down
4 changes: 4 additions & 0 deletions license-maven-plugin-svn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
</site>
</distributionManagement>

<properties>
<jacoco.minimum.coverage>0.00</jacoco.minimum.coverage>
</properties>

<dependencies>
<dependency>
<groupId>com.mycila</groupId>
Expand Down
11 changes: 11 additions & 0 deletions license-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<tag>HEAD</tag>
</scm>

<properties>
<jacoco.minimum.coverage>0.76</jacoco.minimum.coverage>
</properties>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -195,6 +199,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Stream;

import static com.mycila.maven.plugin.license.header.HeaderType.APOSTROPHE_STYLE;
import static com.mycila.maven.plugin.license.header.HeaderType.ASCIIDOC_STYLE;
Expand Down Expand Up @@ -74,7 +75,7 @@
*/
class CompleteMojoTest {

private static Iterable<Object[]> parameters() {
private static Stream<Object[]> parameters() {
final List<Object[]> parameters = asList(new Object[][]{
{ASCIIDOC_STYLE, "adoc"},
{MVEL_STYLE, "mv"},
Expand Down Expand Up @@ -120,20 +121,12 @@ private static Iterable<Object[]> parameters() {
Assertions.fail("Missing test cases: " + set);
}

return parameters;
}

private final String extension;
private final HeaderType headerType;

public CompleteMojoTest(HeaderType headerType, String extension) {
this.extension = extension;
this.headerType = headerType;
return parameters.stream();
}

@ParameterizedTest
@MethodSource("parameters")
void test_add(String name, HeaderType headerType) throws Exception {
void test_add(HeaderType headerType, String extension) throws Exception {
File tmp = new File("target/test/complete/" + headerType + "/test_add");
FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp);

Expand All @@ -153,7 +146,7 @@ void test_add(String name, HeaderType headerType) throws Exception {

@ParameterizedTest
@MethodSource("parameters")
void test_update(String name) throws Exception {
void test_update(HeaderType headerType, String extension) throws Exception {
File tmp = new File("target/test/complete/" + headerType + "/test_update");
FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp);

Expand Down Expand Up @@ -182,7 +175,7 @@ void test_update(String name) throws Exception {

@ParameterizedTest
@MethodSource("parameters")
void test_remove(String name) throws Exception {
void test_remove(HeaderType headerType, String extension) throws Exception {
File tmp = new File("target/test/complete/" + headerType + "/test_remove");
FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp);

Expand Down Expand Up @@ -212,7 +205,7 @@ void test_remove(String name) throws Exception {

@ParameterizedTest
@MethodSource("parameters")
void test_check_failed(String name) throws Exception {
void test_check_failed(HeaderType headerType, String extension) throws Exception {
File tmp = new File("target/test/complete/" + headerType + "/test_check_failed");
FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp);

Expand All @@ -234,7 +227,7 @@ void test_check_failed(String name) throws Exception {

@ParameterizedTest
@MethodSource("parameters")
void test_check_success(String name) throws Exception {
void test_check_success(HeaderType headerType, String extension) throws Exception {
File tmp = new File("target/test/complete/" + headerType + "/test_check_success");
FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void test_styles() throws Exception {
Header header = new Header(new UrlHeaderSource(getClass().getResource("/test-header1.txt"), "UTF-8"), null);
for (HeaderDefinition definition : HeaderType.defaultDefinitions().values()) {
final String content = FileUtils.read(new File(format("src/test/resources/styles/%s.txt", definition.getType())), System.getProperty("file.encoding"));
Assertions.assertEquals("Bad header for type: " + definition.getType(), content, header.buildForDefinition(definition, !containsWindowsLineEnding(content)));
Assertions.assertEquals(content, header.buildForDefinition(definition, !containsWindowsLineEnding(content)), "Bad header for type: " + definition.getType());
}
}

Expand Down
Loading