-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1933 from jplag/feature/cliTests
Added missing CLI tests
- Loading branch information
Showing
9 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
import de.jplag.options.JPlagOptions; | ||
|
||
class DebugTest extends CliTest { | ||
@Test | ||
void testDefaultDebug() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(); | ||
assertFalse(options.debugParser()); | ||
} | ||
|
||
@Test | ||
void testSetDebug() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.DEBUG, true)); | ||
assertTrue(options.debugParser()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
import de.jplag.options.JPlagOptions; | ||
|
||
class ExcludeFileTest extends CliTest { | ||
private static final String EXCLUDE_FILE_NAME = "exclusions"; | ||
|
||
@Test | ||
void testNoDefaultExcludeFile() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(); | ||
assertNull(options.exclusionFileName()); | ||
} | ||
|
||
@Test | ||
void testSetExcludeFile() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.EXCLUDE_FILES, EXCLUDE_FILE_NAME)); | ||
assertEquals(EXCLUDE_FILE_NAME, options.exclusionFileName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.event.Level; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
|
||
class LogLevelTest extends CliTest { | ||
private static final Level DEFAULT_LOG_LEVEL = Level.INFO; | ||
|
||
@Test | ||
void testDefaultLogLevel() throws IOException, ExitException { | ||
Level level = runCliForLogLevel(); | ||
assertEquals(DEFAULT_LOG_LEVEL, level); | ||
} | ||
|
||
@Test | ||
void testSetLogLevel() throws IOException, ExitException { | ||
Level level = runCliForLogLevel(args -> args.with(CliArgument.LOG_LEVEL, Level.ERROR.name())); | ||
assertEquals(Level.ERROR, level); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
|
||
class ResultFileTest extends CliTest { | ||
private static final String DEFAULT_RESULT_FILE = "results.zip"; | ||
private static final String TEST_RESULT_FILE = "customResults.zip"; | ||
private static final String TEST_RESULT_FILE_WITH_AVOIDANCE = "customResults(1).zip"; | ||
private static final String TEST_RESULT_FILE_WITHOUT_ZIP = "customResults"; | ||
|
||
@Test | ||
void testDefaultResultFolder() throws IOException, ExitException { | ||
String targetPath = runCliForTargetPath(); | ||
assertEquals(DEFAULT_RESULT_FILE, targetPath); | ||
} | ||
|
||
@Test | ||
void testSetResultFolder() throws IOException, ExitException { | ||
String targetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, TEST_RESULT_FILE)); | ||
assertEquals(TEST_RESULT_FILE, targetPath); | ||
} | ||
|
||
@Test | ||
void testSetResultFolderWithoutZip() throws IOException, ExitException { | ||
String targetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, TEST_RESULT_FILE_WITHOUT_ZIP)); | ||
assertEquals(TEST_RESULT_FILE, targetPath); | ||
} | ||
|
||
@Test | ||
void testResultFileOverrideAvoidance() throws IOException, ExitException { | ||
File testDir = Files.createTempDirectory("JPlagResultFileTest").toFile(); | ||
File targetFile = new File(testDir, TEST_RESULT_FILE); | ||
File expectedTargetFile = new File(testDir, TEST_RESULT_FILE_WITH_AVOIDANCE); | ||
targetFile.createNewFile(); | ||
|
||
String actualTargetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, targetFile.getAbsolutePath())); | ||
|
||
targetFile.delete(); | ||
testDir.delete(); | ||
|
||
assertEquals(expectedTargetFile.getAbsolutePath(), actualTargetPath); | ||
} | ||
|
||
@Test | ||
void testResultFileOverwrite() throws IOException, ExitException { | ||
File testDir = Files.createTempDirectory("JPlagResultFileTest").toFile(); | ||
File targetFile = new File(testDir, TEST_RESULT_FILE); | ||
targetFile.createNewFile(); | ||
|
||
String actualTargetPath = runCliForTargetPath( | ||
args -> args.with(CliArgument.RESULT_FILE, targetFile.getAbsolutePath()).with(CliArgument.OVERWRITE_RESULT_FILE, true)); | ||
|
||
targetFile.delete(); | ||
testDir.delete(); | ||
|
||
assertEquals(targetFile.getAbsolutePath(), actualTargetPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
import de.jplag.options.JPlagOptions; | ||
|
||
class SubdirectoryTest extends CliTest { | ||
private static final String TEST_SUBDIRECTORY = "dir"; | ||
|
||
@Test | ||
void testDefaultSubdirectory() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(); | ||
assertNull(options.subdirectoryName()); | ||
} | ||
|
||
@Test | ||
void testSetSubdirectory() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.SUBDIRECTORY, TEST_SUBDIRECTORY)); | ||
assertEquals(TEST_SUBDIRECTORY, options.subdirectoryName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.jplag.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.cli.test.CliArgument; | ||
import de.jplag.cli.test.CliTest; | ||
import de.jplag.exceptions.ExitException; | ||
import de.jplag.options.JPlagOptions; | ||
|
||
class SuffixesTest extends CliTest { | ||
private static final List<String> JAVA_SUFFIXES = List.of(".java", ".JAVA"); | ||
private static final List<String> CUSTOM_SUFFIXES = List.of(".j", ".jva"); | ||
|
||
@Test | ||
void testDefaultSuffixes() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(); | ||
assertEquals(JAVA_SUFFIXES, options.fileSuffixes()); | ||
} | ||
|
||
@Test | ||
void testSetSuffixes() throws IOException, ExitException { | ||
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.SUFFIXES, CUSTOM_SUFFIXES.toArray(new String[0]))); | ||
assertEquals(CUSTOM_SUFFIXES, options.fileSuffixes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package de.jplag.cli.test; | ||
|
||
import org.slf4j.event.Level; | ||
|
||
import de.jplag.options.JPlagOptions; | ||
|
||
public record CliResult(JPlagOptions jPlagOptions, String targetPath) { | ||
public record CliResult(JPlagOptions jPlagOptions, String targetPath, Level logLevel) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters