### Question:
SakuliExceptionHandler { void saveException(Exception e) { if (e instanceof SakuliException) { if (((SakuliException) e).getAsyncTestDataRef().isPresent()) { ((SakuliException) e).getAsyncTestDataRef().get().addException(e); return; } } if (loader.getCurrentTestCase() != null) { if (loader.getCurrentTestCaseStep() != null) { loader.getCurrentTestCaseStep().addException(e); loader.getCurrentTestCaseStep().addActions(loader.getCurrentTestCase().getAndResetTestActions()); } else { loader.getCurrentTestCase().addException(e); } } else { loader.getTestSuite().addException(e); } loader.getTestSuite().refreshState(); }  static List<Exception> getAllExceptions(TestSuite testSuite); static Path getScreenshotFile(Exception e); static Exception castTo(SakuliException e); void handleException(Exception e); boolean isAlreadyProcessed(Exception e); boolean resumeToTestExecution(Exception e); void handleException(Exception e, boolean resumeOnException); void handleException(String exceptionMessage, boolean resumeOnException); void handleException(String exceptionMessage, RegionImpl lastRegion, boolean resumeOnException); void handleException(Exception e, RegionImpl lastRegion, boolean resumeOnException); void handleException(LogResult logResult);  }### Answer:
@Test public void testSaveExceptionToAsyncRef() throws Exception { TestSuite ts = new TestSuite(); final SakuliCheckedException e = new SakuliCheckedException("test"); e.setAsyncTestDataRef(ts); testling.saveException(e); assertEquals(ts.getException().getMessage(), "test"); verify(loader, never()).getTestSuite(); }
@Test public void testSaveExceptionsInSuite() throws Exception { TestSuite ts = new TestSuite(); when(loader.getTestSuite()).thenReturn(ts); testling.saveException(new SakuliCheckedException("test")); assertEquals(ts.getException().getMessage(), "test"); }
@Test public void testSaveExceptionsInCase() throws Exception { TestSuite ts = new TestSuite(); when(loader.getTestSuite()).thenReturn(ts); TestCase tc = new TestCase(null, null); when(loader.getCurrentTestCase()).thenReturn(tc); testling.saveException(new SakuliCheckedException("test")); assertNull(ts.getException()); assertEquals(tc.getException().getMessage(), "test"); }
@Test public void testSaveExceptionsInStep() throws Exception { TestSuite ts = new TestSuite(); when(loader.getTestSuite()).thenReturn(ts); TestCase tc = new TestCase(null, null); when(loader.getCurrentTestCase()).thenReturn(tc); TestCaseStep step = new TestCaseStep(); when(loader.getCurrentTestCaseStep()).thenReturn(step); testling.saveException(new SakuliCheckedException("test")); assertNull(ts.getException()); assertNull(tc.getException()); assertEquals(step.getException().getMessage(), "test"); }