In Java, if you want to verify that a method of a non-mock object is called, you typically cannot use a mocking framework like Mockito because it's designed for testing interactions with mock objects. Instead, you can rely on other techniques, such as subclassing or using a testing framework that supports spying or tracking method calls.
Here's an example using a custom subclass and JUnit to verify that a method of a non-mock object is called:
Suppose you have a class MyService with a method doSomething() that you want to verify is called:
public class MyService { public void doSomething() { // Some implementation } } You can create a custom subclass of MyService that overrides the doSomething() method to record whether it's called. Here's an example:
public class MyServiceSpy extends MyService { private boolean doSomethingCalled = false; @Override public void doSomething() { super.doSomething(); // Optional: Call the original method if needed doSomethingCalled = true; } public boolean isDoSomethingCalled() { return doSomethingCalled; } } Now, you can write a JUnit test to verify that the doSomething() method is called:
import org.junit.Test; import static org.junit.Assert.assertTrue; public class MyServiceTest { @Test public void testDoSomething() { MyServiceSpy myService = new MyServiceSpy(); // Call the method you want to test myService.doSomething(); // Verify that the method was called assertTrue(myService.isDoSomethingCalled()); } } In this example, we created a subclass MyServiceSpy that extends MyService and overrides the doSomething() method to track whether it's called. In the test, we instantiate MyServiceSpy, call the method, and then use an assertion to verify that the isDoSomethingCalled() method returns true.
This approach allows you to verify method calls on non-mock objects without using a mocking framework.
pythonpath xcopy cardview user-permissions codable ssl-certificate wifi kana tfvc excel