JMockit mock not getting destroyed
<p>Using JUnit for testing classes-</p>

<p>Have a class <code>TestAccess.java</code> having </p>

<pre><code>static private TestAccess instance = new TestAccess();
public static TestAccess getTestAccess() {
    returns instance;
}
</code></pre>

<p>For testing a test class <code>A.java</code> used JMockit to mock the <code>getTestAccess</code> method</p>

<pre><code>@Mock
TestAccess mockTestaccess;    

@Test
public void testMethod() {
    new MockUp&lt;TestAccess&gt;() {
        @mockit.Mock
        public TestAccess getTestAccess() {
            return mockTestaccess;
        }
    };

    TestAccess test=TestAccess.getTestAccess();
}
</code></pre>

<p>In another class <code>B.java</code> I don't want to use mock and call
<code>TestAccess.java</code> as follows</p>

<pre><code>@Test
public void doTest()
{ 
    TestAccess test=TestAccess.getTestAccess();
}
</code></pre>

<p><code>B.java</code> if run independently, the real <code>TestAccess</code> instance is returned and works fine. </p>

<p>However during maven run it fails as even in <code>B.java</code> the
<code>TestAccess.getTestAccess()</code> return the mock defined in <code>A.java</code> and not the real instance as expected.</p>

<p>Could anyone guide how can this be resolved.</p>