示例#1
0
  @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);
  }
示例#2
0
  @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);
  }
示例#3
0
  @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);
  }
示例#4
0
  @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);
  }