-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added unit tests * added annotations to BatchProcessor because it did not fail fast on a missing action * more informative (error)message * new method batchProcessor in AbstractSubcommandContainer can replace builder methods for all commands but one
- Loading branch information
Showing
10 changed files
with
961 additions
and
10 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
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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/nl/knaw/dans/dvcli/AbstractCapturingTest.java
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,71 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvcli; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
|
||
public abstract class AbstractCapturingTest { | ||
private final PrintStream originalStdout = System.out; | ||
private final PrintStream originalStderr = System.err; | ||
protected OutputStream stdout; | ||
protected OutputStream stderr; | ||
protected ListAppender<ILoggingEvent> logged; | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
|
||
System.setOut(originalStdout); | ||
System.setErr(originalStderr); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
stdout = captureStdout(); | ||
stderr = captureStderr(); | ||
logged = captureLog(Level.DEBUG, "nl.knaw.dans"); | ||
} | ||
|
||
public static ListAppender<ILoggingEvent> captureLog(Level error, String loggerName) { | ||
var logger = (Logger) LoggerFactory.getLogger(loggerName); | ||
ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); | ||
listAppender.start(); | ||
logger.setLevel(error); | ||
logger.addAppender(listAppender); | ||
return listAppender; | ||
} | ||
|
||
public static ByteArrayOutputStream captureStdout() { | ||
var outContent = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(outContent)); | ||
return outContent; | ||
} | ||
|
||
public static ByteArrayOutputStream captureStderr() { | ||
var outContent = new ByteArrayOutputStream(); | ||
System.setErr(new PrintStream(outContent)); | ||
return outContent; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/nl/knaw/dans/dvcli/AbstractTestWithTestDir.java
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,36 @@ | ||
package nl.knaw.dans.dvcli;/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* A test class that creates a test directory for each test method. | ||
*/ | ||
public abstract class AbstractTestWithTestDir { | ||
protected final Path testDir = Path.of("target/test") | ||
.resolve(getClass().getSimpleName()); | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
if (testDir.toFile().exists()) { | ||
// github stumbled: https://github.com/DANS-KNAW/dans-layer-store-lib/actions/runs/8705753485/job/23876831089?pr=7#step:4:106 | ||
FileUtils.deleteDirectory(testDir.toFile()); | ||
} | ||
} | ||
} |
Oops, something went wrong.