@Test
  public void testEnqueue() {
    final String[] putSomethingHere = new String[] {null};
    final String something = "Something";

    Runnable myRunnable =
        new Runnable() {
          public void run() {
            synchronized (this) {
              putSomethingHere[0] = something;
              this.notify();
            }
          }
        };
    try {
      RunnableQueue.enqueue(myRunnable);
      synchronized (myRunnable) {
        while (putSomethingHere[0] == null) {
          myRunnable.wait();
        }
      }
    } catch (InterruptedException e) {
      throw new AssertionError("Thread unexpectedly interrupted during enqueue");
    }
    assertEquals(putSomethingHere[0], something);
  }
Example #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);
  }
Example #3
0
 private <E extends RuntimeException> void assertRunnable(Runnable test, Class<E> type) {
   assertNotNull(test);
   try {
     test.run();
     fail();
   } catch (RuntimeException e) {
     assertException(type, e, "runnable");
   }
 }
 /**
  * Steps tested:
  *
  * <p>select -> run (if not null) -> invokeBehavior(method) -> test selection/focus state
  *
  * @param method the name of the method do invoke in behaviour
  * @param selectedIndex the index to select
  * @param expectedIndex the expected index after running and invoking
  * @param run the action to run after selecting, may be null to do nothing
  * @throws Exception
  */
 protected void assertBehaviorSelectionMovedWithModification(
     String method, int selectedIndex, int expectedIndex, Runnable run) throws Exception {
   initSkin();
   getSelectionModel().select(selectedIndex);
   if (run != null) run.run();
   invokeBehavior(method);
   assertEquals(method + " selected index must be moved", expectedIndex, getSelectedIndex());
   assertEquals(method + " focus must same as selected index", expectedIndex, getFocusedIndex());
   assertEquals(method + " selection size must be one", 1, getSelectedIndices().size());
   assertEquals(method + " anchor must be same as focus", expectedIndex, getAnchorIndex());
 }
 @Override
 public void execute(final Runnable command) {
   command.run();
 }
 public void generate(Project project) throws IOException {
   generator.run();
 }