@@ -21,11 +21,13 @@ public class LoggerTest {
2121 private final Path logPath ;
2222 private final Logger logger ;
2323 private final PrintStream printStreamMock ;
24+ private final FileOperator fileOperatorMock ;
2425
2526 public LoggerTest () throws IOException {
2627 logPath = Paths .get (tempDir ().toString (), "logs" );
2728 printStreamMock = mock (PrintStream .class );
2829 logger = new Logger (logPath , new FileOperator (), printStreamMock );
30+ fileOperatorMock = mock (FileOperator .class );
2931 }
3032
3133 @ Test
@@ -50,12 +52,18 @@ public void writesToLogAndReadsFromLog() throws Exception {
5052
5153 @ Test
5254 public void printsErrorToStdErrIfCantWriteToLog () throws Exception {
53- FileOperator fileOperatorMock = mock (FileOperator .class );
5455 doThrow (new IOException ()).when (fileOperatorMock ).appendToFile (any (), any ());
5556 Logger logger = new Logger (logPath , fileOperatorMock , printStreamMock );
5657
5758 logger .log ("" );
5859
5960 verify (printStreamMock ).print (any (Exception .class ));
6061 }
62+
63+ @ Test (expected = RuntimeException .class )
64+ public void throwsRuntimeExceptionIfCantCreateLogFile () throws Exception {
65+ doThrow (new IOException ()).when (fileOperatorMock ).createFileAtPath (any ());
66+
67+ Logger logger = new Logger (logPath , fileOperatorMock , printStreamMock );
68+ }
6169}
0 commit comments