[MAGNOLIA-1159] testing: facilitate usage of mocks Created: 25/Oct/06 Updated: 23/Jan/13 Resolved: 25/Oct/06 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | 3.0 RC3 |
| Fix Version/s: | 3.0 RC4 |
| Type: | Improvement | Priority: | Major |
| Reporter: | Philipp Bärfuss | Assignee: | Philipp Bärfuss |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Acceptance criteria: |
Empty
|
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
| Date of First Response: |
| Description |
|
We should allow to use mocks created with EasyMocks in the FactoryUtil. Currently the FactoryUtil instantiates an object by itslef and one can only define the implementation class (works really fine), but for testing it would be nice if we could register mocks with a method registerMock() and switch them on with setMocksAllowed(). Using this we are able to mock the major parts in magnolia. |
| Comments |
| Comment by Philipp Bracher [ 25/Oct/06 ] |
|
Thought so This code here won't work: ModuleLoader loader = createMock(ModuleLoader.class); because createMock(ModuleLoader.class) triggers already the call to FactoryUtil.getSingleton() before we were able to register the mock. This happens because of this line: private static ModuleLoader instance = (ModuleLoader) FactoryUtil.getSingleton(ModuleLoader.class); If we use the appoach described above (I think we should, because it is easy to use), we need to lazy bind the instance variables. |
| Comment by Philipp Bracher [ 25/Oct/06 ] |
|
I did a few things to solve this:
The following test is now working fine: ModuleLoader loader = createMock(ModuleLoader.class); |
| Comment by Philipp Bracher [ 25/Oct/06 ] |
|
I did alos rename getInstance() to newInstance (getInstace is deprecated but working) |
| Comment by Philipp Bracher [ 25/Oct/06 ] |
|
done |