package no.saua.remock;

import no.saua.remock.exampleapplication.AnInterfaceImplOne;
import no.saua.remock.exampleapplication.AnInterfaceImplTwo;
import no.saua.remock.exampleapplication.SomeService;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.springframework.test.context.ContextConfiguration;

import javax.inject.Inject;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

/**
 * Checks that Mocks and spies are reset after every test-method. Note that the ordering of the test are significant.
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ContextConfiguration(classes = {SomeService.class, AnInterfaceImplOne.class, AnInterfaceImplTwo.class})
public class ResetTest extends CommonTest {

    @Inject
    @ReplaceWithMock
    public AnInterfaceImplOne mock;

    @Inject
    @WrapWithSpy(AnInterfaceImplTwo.class)
    public AnInterfaceImplTwo spy;

    @Test
    public void testA_DirtiesMocks() {
        assertEquals(null, mock.someMethod());
        when(mock.someMethod()).thenReturn("abc");
        assertEquals("abc", mock.someMethod());

        assertEquals("someMethodTwo", spy.someMethod());
        doReturn("xyz").when(spy).someMethod();
        assertEquals("xyz", spy.someMethod());
    }

    @Test
    public void testB_ChecksThatMocksAreNotDirty() {
        assertEquals(null, mock.someMethod());
        assertEquals("someMethodTwo", spy.someMethod());
    }
}

@@ -140,16 +140,77 @@
 mplTwo;%0A
+import no.saua.remock.exampleapplication.ExampleFactoryBean;%0A
 import n
@@ -255,16 +255,16 @@
 ervice;%0A
-
 import o
@@ -418,37 +418,8 @@
 n;%0A%0A
-import javax.inject.Inject;%0A%0A
 impo
@@ -866,28 +866,16 @@
 Test %7B%0A%0A
-    @Inject%0A
     @Rep
@@ -928,20 +928,8 @@
 k;%0A%0A
-    @Inject%0A
     
@@ -1003,16 +1003,115 @@
 o spy;%0A%0A
+    @ReplaceWithMock%0A    public ExampleFactoryBean.BeanFromFactoryBean mockOfBeanFromFactoryBean;%0A%0A
     @Tes
@@ -1445,24 +1445,240 @@
 meMethod());
+%0A%0A        assertEquals(null, mockOfBeanFromFactoryBean.someMethod());%0A        when(mockOfBeanFromFactoryBean.someMethod()).thenReturn(%22mocked%22);%0A        assertEquals(%22mocked%22, mockOfBeanFromFactoryBean.someMethod());
 %0A    %7D%0A%0A    
@@ -1775,32 +1775,32 @@
 .someMethod());%0A
-
         assertEq
@@ -1836,20 +1836,88 @@
 eMethod());%0A
+        assertEquals(null, mockOfBeanFromFactoryBean.someMethod());%0A
     %7D%0A%7D%0A

Verify that a mocked result of FactoryBean is reset