Update RolloverFileOutputStreamTest.java
Simplified test class as suggested
This commit is contained in:
parent
c338c1a153
commit
40a31b8394
|
@ -36,7 +36,10 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
@ExtendWith(WorkDirExtension.class)
|
@ExtendWith(WorkDirExtension.class)
|
||||||
public class RolloverFileOutputStreamTest
|
public class RolloverFileOutputStreamTest
|
||||||
|
@ -185,41 +188,21 @@ public class RolloverFileOutputStreamTest
|
||||||
public void testMissingDirectory()
|
public void testMissingDirectory()
|
||||||
{
|
{
|
||||||
|
|
||||||
ZoneId zone = toZoneId("Australia/Sydney");
|
|
||||||
ZonedDateTime now = toDateTime("2016.04.10-08:30:12.3 AM AEDT", zone);
|
|
||||||
String templateString = "missingDir/test-rofos-yyyy_mm_dd.log";
|
String templateString = "missingDir/test-rofos-yyyy_mm_dd.log";
|
||||||
String excMessageExpected = "Log directory does not exist.";
|
String excMessageActual = null;
|
||||||
|
Throwable error = null;
|
||||||
try (RolloverFileOutputStream rofos =
|
try (RolloverFileOutputStream rofos = new RolloverFileOutputStream(templateString))
|
||||||
new RolloverFileOutputStream(templateString, false, 3, TimeZone.getTimeZone(zone), null, null, now))
|
|
||||||
{
|
{
|
||||||
rofos.write("TICK".getBytes());
|
throw new IllegalStateException();
|
||||||
rofos.flush();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
boolean exClassOK = false;
|
error = t;
|
||||||
if (ex instanceof java.io.IOException)
|
excMessageActual = t.getMessage();
|
||||||
{
|
|
||||||
exClassOK = true;
|
|
||||||
}
|
|
||||||
assertThat("Exception Type", exClassOK, is(true));
|
|
||||||
|
|
||||||
String excMessageActual = ex.getMessage();
|
|
||||||
boolean messageOK = false;
|
|
||||||
if (excMessageActual != null)
|
|
||||||
{
|
|
||||||
excMessageActual = excMessageActual.trim();
|
|
||||||
if (!excMessageActual.isEmpty())
|
|
||||||
{
|
|
||||||
if (excMessageActual.contains(excMessageExpected))
|
|
||||||
{
|
|
||||||
messageOK = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertThat("Exception Message", messageOK, is(true));
|
|
||||||
}
|
}
|
||||||
|
assertNotNull(error);
|
||||||
|
assertThat(error, instanceOf(IOException.class));
|
||||||
|
assertThat(excMessageActual, containsString("Log directory does not exist."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue