Skip to content

Commit

Permalink
✅ Add a test for trying to load a non-existing file
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Nov 4, 2024
1 parent f7018d4 commit 013c92c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/java/swiss/fihlon/apus/event/TrackTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package swiss.fihlon.apus.event;

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -15,6 +21,19 @@

class TrackTest {

private final PrintStream standardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();

@BeforeEach
public void setUp() {
System.setOut(new PrintStream(outputStreamCaptor));
}

@AfterEach
public void tearDown() {
System.setOut(standardOut);
}

@Test
void noneTrack() {
final Track testee = new Track(null);
Expand Down Expand Up @@ -50,4 +69,15 @@ void customTrack() {
assertEquals("testSvgCode", testee.svgCode());
}

@Test
void customTrackLogException() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Method defaultTrackMethod = Track.class.getDeclaredMethod("defaultTrack", String.class);
defaultTrackMethod.setAccessible(true);
final var track = defaultTrackMethod.invoke(String.class, "non-existing-file.svg");
assertEquals(Track.NONE, track);

final String out = outputStreamCaptor.toString();
assertTrue(out.contains("Unable to load default track icon 'non-existing-file.svg':"));
}

}

0 comments on commit 013c92c

Please sign in to comment.