@Test
  public void removeModelsLoadedByTheTemporaryEditingContextAfterTestExecution() throws Throwable {
    AbstractEditingContextRule editingContext = createEditingContext(TEST_MODEL_NAME);

    editingContext.before(mockTarget);
    editingContext.after(mockTarget);

    assertThat(EOModelGroup.defaultGroup().modelNamed(TEST_MODEL_NAME), nullValue());
  }
  @Test
  public void lockEditingContextBeforeRunningTheTestCase() throws Exception {
    AbstractEditingContextRule editingContext = spy(createEditingContext());

    verify(editingContext, times(0)).lock();

    editingContext.before(mockTarget);

    verify(editingContext, times(1)).lock();
  }
  @Test
  public void disposeEditingContextAfterTestExecution() throws Throwable {
    AbstractEditingContextRule editingContext = Mockito.spy(createEditingContext(TEST_MODEL_NAME));

    editingContext.before(mockTarget);

    Mockito.verify(editingContext, Mockito.times(0)).dispose();

    editingContext.after(mockTarget);

    Mockito.verify(editingContext, Mockito.times(1)).dispose();
  }
  @Test
  @Ignore(value = "Revert may not be necessary")
  public void revertEditingContextChangesAfterRunningTheTestCases() throws Exception {
    AbstractEditingContextRule editingContext = spy(createEditingContext());

    editingContext.before(mockTarget);

    verify(editingContext, times(0)).revert();

    editingContext.after(mockTarget);

    verify(editingContext, times(1)).revert();
  }
  @Test
  public void doNotRemoveModelsNotLoadedByTheEditingContextRule() throws Throwable {
    URL url = getClass().getResource("/" + TEST_MODEL_NAME + ".eomodeld");

    EOModelGroup.defaultGroup().addModelWithPathURL(url);

    AbstractEditingContextRule editingContext = createEditingContext();

    editingContext.before(mockTarget);
    editingContext.after(mockTarget);

    assertThat(EOModelGroup.defaultGroup().modelNamed(TEST_MODEL_NAME), notNullValue());
  }
  @Test
  public void cannotCreateObjectUnderTestForNonEnterpriseObjectFields() throws Exception {
    AbstractEditingContextRule editingContext = createEditingContext(TEST_MODEL_NAME);

    WrongTypeForUnderTestStubTestCaseClass mockTarget =
        new WrongTypeForUnderTestStubTestCaseClass();

    thrown.expect(WOUnitException.class);
    thrown.expectMessage(
        is(
            "Cannot create object of type java.lang.String.\n Only fields of type com.webobjects.eocontrol.EOEnterpriseObject can be annotated with @UnderTest."));

    editingContext.before(mockTarget);
  }
  @Test
  @SuppressWarnings("unchecked")
  public void createAndInsertObjectForFieldAnnotatedWithUnderTest() throws Exception {
    AbstractEditingContextRule editingContext = createEditingContext(TEST_MODEL_NAME);

    StubTestCaseClass mockTestCase = new StubTestCaseClass();

    editingContext.before(mockTestCase);

    EOEnterpriseObject objectUnderTest = mockTestCase.objectUnderTest();

    assertThat(objectUnderTest, notNullValue());

    NSArray<EOEnterpriseObject> insertedObjects = editingContext.insertedObjects();

    assertThat(insertedObjects, hasItem(objectUnderTest));
  }
  @Test
  public void clearEditingContextChangesAfterTestExecution() throws Exception {
    AbstractEditingContextRule editingContext = createEditingContext(TEST_MODEL_NAME);

    editingContext.before(mockTarget);

    FooEntity foo = FooEntity.createFooEntity(editingContext);

    foo.setBar("test");

    editingContext.saveChanges();

    editingContext.after(mockTarget);

    editingContext = createEditingContext(TEST_MODEL_NAME);

    NSArray<FooEntity> result = FooEntity.fetchAllFooEntities(editingContext);

    assertThat(result.isEmpty(), is(true));
  }