/** Tests whether an exception is reported to the observer. */
 @Test
 public void testOnException() throws ConcurrentException {
   EntityManager em = EasyMock.createMock(EntityManager.class);
   EntityTransaction tx = EasyMock.createNiceMock(EntityTransaction.class);
   EasyMock.expect(em.getTransaction()).andReturn(tx).anyTimes();
   EasyMock.expect(init.get().createEntityManager()).andReturn(em);
   final RuntimeException err = new RuntimeException("TestException");
   observer.commandExecutionFailed(err);
   EasyMock.replay(em, tx, observer, init.get());
   ObservableCommandTestImpl cmd =
       new ObservableCommandTestImpl(init, observer, em) {
         @Override
         protected String produceResults(EntityManager em) {
           super.produceResults(em);
           throw err;
         }
       };
   try {
     cmd.execute();
     fail("Exception not thrown!");
   } catch (Exception ex) {
     assertEquals("Wrong exception", err, ex);
   }
   cmd.onException(err);
   EasyMock.verify(em, tx, observer, init.get());
 }
 /** Tests whether the observer is correctly notified after executing a JPA operation. */
 @Test
 public void testExecuteJPAOperation() {
   EntityManager em = EasyMock.createMock(EntityManager.class);
   observer.commandCompletedBackground(RESULT);
   EasyMock.replay(em, observer);
   ObservableCommandTestImpl cmd = new ObservableCommandTestImpl(init, observer, em);
   cmd.executeJPAOperation(em);
   assertEquals("Results not available", RESULT, cmd.getResult());
   EasyMock.verify(em, observer);
 }
 /** Tests whether the observer is correctly notified on the event dispatch thread. */
 @Test
 public void testPerformGUIUpdate() {
   final Throwable err = new RuntimeException();
   observer.commandCompletedUI(RESULT, err);
   EasyMock.replay(observer);
   ObservableCommandTestImpl cmd =
       new ObservableCommandTestImpl(init, observer) {
         @Override
         String getResult() {
           return RESULT;
         }
       };
   cmd.setException(err);
   cmd.performGUIUpdate();
   EasyMock.verify(observer);
 }