You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EasyMockSupport and EasyMockRule/EasyMockRunner are great features that work well together when EasyMockSupport is used through inheritence.
However when using EasyMockSupport through delegation, it's currently (almost) impossible to make EasyMockRule aware of it, so mocks created with @Mock aren't taken into account by EasyMockSupport.
Here is a code snippet demonstrating the issue:
importorg.easymock.*;
importorg.junit.*;
// Class under testpublicclassMyClass {
privateCollaboratorcollaborator;
publicMyClass() {
collaborator = newCollaborator();
}
// Method under testpublicintmyMethod() {
returncollaborator.mockedMethod() + 1;
}
}
// Class to be mockedpublicclassCollaborator {
publicintmockedMethod() {
return1;
}
}
// Test casepublicclassMyClassTest { // May extend another classprivateEasyMockSupporteasyMockSupport = newEasyMockSupport();
@RulepublicEasyMockRuleeasyMockRule = newEasyMockRule(this);
@TestSubjectprivateMyClasstestSubject = newMyClass();
@MockprivateCollaboratorcollaboratorMock;
@TestpublicvoidtestMyMethod() {
EasyMock.expect(collaboratorMock.mockedMethod()).andReturn(2);
easyMockSupport.replayAll();
intresult = testSubject.myMethod();
Assert.assertEquals("Should return 2+1 when successfully mocked", 3, result);
// throws java.lang.AssertionError: expected: <3> but was: <1>
}
}
This is a feature request to make the API provide a way to make EasyMockRule aware of EasyMockSupport.
Ideally, i'd like to have another EasyMockRule constructor with a second EasyMockSupport parameter. So we could write this:
EasyMockSupport
andEasyMockRule
/EasyMockRunner
are great features that work well together whenEasyMockSupport
is used through inheritence.However when using
EasyMockSupport
through delegation, it's currently (almost) impossible to makeEasyMockRule
aware of it, so mocks created with@Mock
aren't taken into account byEasyMockSupport
.Here is a code snippet demonstrating the issue:
This is a feature request to make the API provide a way to make
EasyMockRule
aware ofEasyMockSupport
.Ideally, i'd like to have another
EasyMockRule
constructor with a secondEasyMockSupport
parameter. So we could write this:Or an annotation might be a solution to make
EasyMockRunner
work withEasyMockSupport
as well?Thanks for your great work!
The text was updated successfully, but these errors were encountered: