Verifying Static Method Calls
This section explains how to verify mocked static method calls, and why it's important to include them within unit tests. Code Example There may be cases where some code you want to test interacts with an external system, such as a database for example. You wouldn't want to execute the SQL statements within a unit test, especially if the query takes some time. However, we may want to ensure that the mocked DAO is invoked. This can easily be handled with Mockito, but what if the SQL statement is within a static method? That's where verify comes in handy with PowerMock. Below is an example of such a scenario. UnderTest.java 1| package main; 2| 3| public class UnderTest { 4| public void foo() { 5| DAO.executeSQL(); 6| } 7| } Method under test foo() that invokes the SQL statement. DAO.java 1| package main; 2| 3| public class DAO { 4| public static void executeSQL() { 5| System.out.println("Exec...