I was writing junit test using EasyMock .So for a object :-
DataProvider dataProvider = new DataProvider(Data data , Provider provider);
So i had to mock behaviour twice , like this :-
@Mock DataProvider dataProvider1 , dataProvider2;
1. PowerMock.expectNew(DataProvider.class, dataRequest, provider1).thenReturn(mockDataProvider1);
2. PowerMock.replay(DataProvider.class);
3. PowerMock.expectNew(DataProvider.class, dataRequest, provider2).thneReturn(mockDataProvider2);
4. PowerMock.replay(DataProvider.class);
But when i'm trying to execute this . this is throwing error at line number 2 . When i removed line 3 and 4 , it got succeeded without any problem.
and i need to use it twice in my behaviour . Can somebody please help ?
replay() method shouldn't be called twice for same class in same test method.
so :-
1. PowerMock.expectNew(DataProvider.class, dataRequest, provider1).thenReturn(mockDataProvider1);
3. PowerMock.expectNew(DataProvider.class, dataRequest, provider2).thneReturn(mockDataProvider2);
4. PowerMock.replay(DataProvider.class);
This thing worked .
Same suggestion for mockStatic() function as well.
One should also remember to use mockStatic() function only once for a class in one test method. so :-
PowerMock.mockStatic(DataProvider.class);
This should be used only once in a test-method.