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

Add IT for checking the creation of depclean-results.json #84

Merged
merged 8 commits into from
Apr 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ private MavenInvoker() {
* @throws InterruptedException In case of IO issues.
*/
public static String[] runCommand(String cmd) throws IOException, InterruptedException {
String os = System.getProperty("os.name").toLowerCase();
Process process;
ArrayList<String> list;
if (isUnix(os)) {
if (OsUtils.isUnix()) {
list = new ArrayList<>();
process = Runtime.getRuntime().exec(cmd);
InputStream inputStream = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
return outputToConsole(process, list, br);
} else if (isWindows(os)) {
} else if (OsUtils.isWindows()) {
list = new ArrayList<>();
process = Runtime.getRuntime().exec("cmd /C " + cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
Expand All @@ -73,12 +72,4 @@ private static String[] outputToConsole(Process process, ArrayList<String> list,
br.close();
return list.toArray(new String[0]);
}

private static boolean isUnix(String os) {
return (os.contains("nix") || os.contains("nux") || os.contains("mac os"));
}

private static boolean isWindows(String os) {
return (os.contains("win"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package se.kth.depclean.util;

/**
* Utility class to determine the operative system being used.
*/
public class OsUtils {

private static final String OS = System.getProperty("os.name").toLowerCase();

private OsUtils() {
}

public static boolean isUnix() {
return (OS.contains("nix") || OS.contains("nux") || OS.contains("mac os"));
}

public static boolean isWindows() {
return (OS.contains("win"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import com.soebes.itf.jupiter.extension.MavenTest;
import com.soebes.itf.jupiter.maven.MavenExecutionResult;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.DisplayName;
import se.kth.depclean.util.OsUtils;

/**
* This class executes integration tests against the DepCleanMojo. The projects used for testing are in
Expand Down Expand Up @@ -48,17 +52,16 @@ void processor_used(MavenExecutionResult result) {

@MavenTest
@DisplayName("Test that DepClean creates a proper depclean-results.json file")
void json_should_be_correct(MavenExecutionResult result) {
File producedJson =
new File("target/maven-it/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/project/depclean-results.json");
File expectedJson =
new File("src/test/resources/depclean-results.json");
assertThat(result).isSuccessful()
.out()
.plain().contains(
"Creating depclean-results.json, please wait...",
"[INFO] depclean-results.json file created in: " + producedJson.getAbsolutePath());
assertThat(expectedJson).hasSameTextualContentAs(producedJson);
void json_should_be_correct(MavenExecutionResult result) throws IOException {
if (OsUtils.isUnix()) {
File expectedJsonFile = new File("src/test/resources/depclean-results.json");
String expectedJsonContent = FileUtils.readFileToString(expectedJsonFile, Charset.defaultCharset());
assertThat(result).isSuccessful()
.project()
.hasTarget()
.withFile("depclean-results.json")
.hasContent(expectedJsonContent);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.foo.bar</groupId>
<artifactId>foobar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>foobar</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-manifests</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>se.kth.castor</groupId>
<artifactId>depclean-maven-plugin</artifactId>
<version>2.0.2-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>depclean</goal>
</goals>
<configuration>
<createResultJson>true</createResultJson>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org;

import org.apache.commons.codec.Charsets;

public class UseCommonsCodec {

public static void main(String[] args) {
System.out.println(Charsets.UTF_8);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org;

import com.jcabi.manifests.Manifests;

public class UseJcabiManifest {

public static void main(String[] args) {
Manifests manifests = new Manifests();
System.out.println(manifests.size());
}
}
Loading