The @Injectable
mock used in the test does work. However, it is never injected into the tested object, which instead creates its own Student
instance. So, in situations like this you use @Mocked
, not @Injectable
.
I should point out two other things, though:
- Please take notice of the API documentation. The JMockit jar files (even the Maven ones) contain source code precisely to facilitate access to API documentation from any Java IDE.
- "Value classes" like
Student
(which merely contain getters/setters) are not good candidates for mocking. In general, they should not be mocked. Instead, real instances should be used.