Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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);
  }