Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Powermockito static method call

@SpringBootTest
@RunWith(PowerMockTestRunner.class)
@PrepareForTest(value = B.class)
public class TestClass {

    @Test
    public void testBAdmin() {
        String auditUser = "admin";
        Timestamp timestamp = new Timestamp(1577447182l);

        PowerMockito.mockStatic(B.class);
        //You can mock method here, if you need return value like this
        //when(B.testB(timestamp)).thenReturn("some_value");

        A.testA(auditUser, timestamp);

        PowerMockito.verifyStatic(B.class);
        B.testB(timestamp);
    }
    @Test
    public void testBNotAdmin() {
        String auditUser = "not_admin";
        Timestamp timestamp = new Timestamp(1577447182l);

        PowerMockito.mockStatic(B.class);
        //You can mock method here, if you need return value like this
        //when(B.testB(timestamp)).thenReturn("some_value");

        A.testA(auditUser, timestamp);

        PowerMockito.verifyZeroInteractions(B.class);
    }
}
class A {
    public static void testA(String auditUser, Timestamp timestamp) {
        if ("admin".equalsIgnoreCase(auditUser)) {
            B.testB(timestamp);
        }
    }
}

class B {
    public static void testB(Timestamp timestamp) {
//...some logic...//
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java 2 decimals 
Java :: java iterator index 
Java :: initialize an array in java 
Java :: override class java 
Java :: GenerationTarget encountered exception accepting command : Error executing DDL 
Java :: comment générer un nombre aléatoire en java 
Java :: swing getsource 
Java :: java actionperformed 
Java :: java ignore catch 
Java :: compareto in java string 
Java :: hibernate in spring boot 
Java :: read file from resources java 
Java :: save bitmap file for share on android 10 
Java :: icon share android 
Java :: java get class name of object 
Java :: java instantiate a scanner 
Java :: latest android version 
Java :: is it possible to quick sort a string in java 
Java :: how to use string variables with an if statement in java 
Java :: dockerfile for spring boot app 
Java :: how to initialize char in java 
Java :: java bfs 
Java :: Java List Add Elements using add() method 
Java :: android studio reg get float from numeric string 
Java :: java convert ip to long 
Java :: android check free space programmatically 
Java :: how to pass a float between activities in android studio 
Java :: spring mvc project example 
Java :: stack initialization for string java 
Java :: format print java 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =