Beispiel #1
0
  @Test
  public void testCheckNotFinalized3() {
    Runnable task = mock(Runnable.class);

    ObjectFinalizer finalizer = new ObjectFinalizer(task, "DESCRIPTION");
    finalizer.checkNotFinalized();
  }
Beispiel #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();
  }
Beispiel #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();
  }
Beispiel #4
0
  /** Test of doFinalize method, of class ObjectFinalizer. */
  @Test
  public void testDoFinalize() {
    Runnable task = mock(Runnable.class);

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

    verify(task).run();
    verifyNoMoreInteractions(task);
  }
Beispiel #5
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);
  }
Beispiel #6
0
  @Test
  public void testIsFinalized2() {
    Runnable task = mock(Runnable.class);

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

    finalizer.markFinalized();

    assertTrue(finalizer.isFinalized());
  }
Beispiel #7
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);
  }
Beispiel #8
0
 @SuppressWarnings("FinalizeCalledExplicitly")
 private static void finalizeObject(ObjectFinalizer finalizer) {
   finalizer.finalize();
 }