public class MyClass { @Resource private INetworkService networkService; @Resource private IFileService fileService; public boolean SomeMethod(){ // some logic here // More logic here networkService.Send(); return true; } }

@RunWith(MockitoJUnitRunner.class) public class MyClassTest { @Mock private INetworkService networkService; @Mock private IFileService fileService; @InjectMocks MyClass myClass; @Test public void testSomeMethod() { boolean result = myClass.SomeMethod(); assertTrue(result); } }

public class MyClass { @Resource private INetworkService networkService; @Resource private IFileService fileService; private Integer version; public MyClass(Integer version) { this.version = version; } public boolean SomeMethod(){ // some logic here // More logic here networkService.Send(); return true; } }

Labels: Java, Mockito, Unit tests