jeudi 17 décembre 2020

assert a mocked static method is called multiple times each with a specific argument

Not a duplicate I already looked at Mocking static method that is called multiple times, that question, however, is different from mine in that he is seeking partial mocking.

What I want

class A {
   public static void a(int x, int y);   // <-- mock this static method
}

How do I mock the a(x,y) method?

Pseudo code for what I want my test to do:

class TestA {
    @Test
    public void test_method_a_is_called_x_numbers_of_times_each_with_specific_parameters() {
        SUT.exercise()  // I need to verify SUT's behavior by observing the SUT's calls to `a(x,y)`

        // I want to somehow be able to assert: (Psuedo code)
        // First  call to `a(x,y)` was:   a(0,0)
        // Second call to `a(x,y)` was:   a(0,1)
        // Third  call to `a(x,y)` was:   a(0,0)
        // Fourth call to `a(x,y)` was:   a(4,2)

        // You get the idea ...
    }
}

Aucun commentaire:

Enregistrer un commentaire