@Test public void testFinalizeBeforeDoFinalizeTaskFails() { Runnable task = mock(Runnable.class); doThrow(new TestException()).when(task).run(); ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION"); try (LogCollector logs = LogCollectorTest.startCollecting()) { finalizeObject(finalizer); LogCollectorTest.verifyLogCount(TestException.class, Level.SEVERE, 1, logs); } verify(task).run(); verifyNoMoreInteractions(task); }
@Test public void testFinalizeAfterMarkFinalized() { Runnable task = mock(Runnable.class); ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION"); finalizer.markFinalized(); try (LogCollector logs = LogCollectorTest.startCollecting()) { finalizeObject(finalizer); assertEquals(0, logs.getNumberOfLogs()); } verifyZeroInteractions(task); }
@Test public void testFinalizeBeforeDoFinalizeInheritMessage() { Runnable task = mock(Runnable.class); stub(task.toString()).toReturn("DESCRIPTION"); ObjectFinalizer finalizer = new ObjectFinalizer(task); try (LogCollector logs = LogCollectorTest.startCollecting()) { finalizeObject(finalizer); assertEquals(1, logs.getNumberOfLogs()); } verify(task).run(); verifyNoMoreInteractions(task); }
@Test public void testFinalizeBeforeDoFinalize() { Runnable task = mock(Runnable.class); ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION"); try (LogCollector logs = LogCollectorTest.startCollecting()) { finalizeObject(finalizer); assertEquals(1, logs.getNumberOfLogs(Level.SEVERE)); } verify(task).run(); verifyNoMoreInteractions(task); }