Esempio n. 1
0
  @Test
  public void testMultipleDoFinalize() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    assertTrue(finalizer.doFinalize());
    assertFalse(finalizer.doFinalize());

    verify(task).run();
    verifyNoMoreInteractions(task);
  }
Esempio n. 2
0
  /** Test of checkNotFinalized method, of class ObjectFinalizer. */
  @Test(expected = IllegalStateException.class)
  public void testCheckNotFinalized1() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    finalizer.doFinalize();
    finalizer.checkNotFinalized();
  }
Esempio n. 3
0
  @Test(expected = TestException.class)
  public void testDoFinalizePropagatesException() {
    Runnable task = mock(Runnable.class);
    doThrow(TestException.class).when(task).run();

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    finalizer.doFinalize();
  }
Esempio n. 4
0
  /** Test of markFinalized method, of class ObjectFinalizer. */
  @Test
  public void testMarkFinalized() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    finalizer.markFinalized();
    assertFalse(finalizer.doFinalize());

    verifyZeroInteractions(task);
  }
Esempio n. 5
0
  /** Test of isFinalized method, of class ObjectFinalizer. */
  @Test
  public void testIsFinalized1() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    assertFalse(finalizer.isFinalized());

    assertTrue(finalizer.doFinalize());

    assertTrue(finalizer.isFinalized());
  }
Esempio n. 6
0
  @Test
  public void testFinalizeAfterDoFinalize() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    finalizer.doFinalize();
    try (LogCollector logs = LogCollectorTest.startCollecting()) {
      finalizeObject(finalizer);
      assertEquals(0, logs.getNumberOfLogs());
    }

    verify(task).run();
    verifyNoMoreInteractions(task);
  }