mardi 12 novembre 2019

Parameterized tests with JUnitParamsRunner for Mockito.verify() of different methods

So, I have a method that takes an Object parameter and depending on its value invokes different methods (I use just if statements instead of switch).

public class ClassToTest {

    public void methodToTest(String input) {
        if (input.equals("A")) {
            ServiceClass.methodA();
        }
        if (input.contentEquals("B")) {
            ServiceClass.methodB();
        }
        if (input.contentEquals("C")) {
            ServiceClass.methodC();
        }
    }
}
public class ServiceClass {

    public static void methodA() {
        System.out.println("A");
    }

    public static void methodB() {
        System.out.println("B");
    }

    public static void methodC() {
        System.out.println("C");
    }
}

I know that JUnitParamsRunner simplifies writing of parameterized tests and I know about Mockito.verify() to check if specific method was invoked. But in my case is it possible to make a parameterized test of different inputs and check if a respective method have been called? Or is it that for verify() I need to write separate tests for each scenario.

Aucun commentaire:

Enregistrer un commentaire