Exercise 1: Create Your Test Data With the @CsvSource Annotation

This exercise helps you to understand how you can create the test data that’s passed to a parameterized test by using the @CsvSource annotation. Let’s start by taking a quick look at the system under test.

The ProgrammingLanguage enum specifies different programming languages. Its source code looks as follows:

public enum ProgrammingLanguage {

    C,
    CLOJURE,
    SMALLTALK
}

The ProgrammingParadigm enum specifies different programming paradigms. It also has one static method called fromProgrammingLanguage(). This method returns the programming paradigm that’s used by the programming language given as a method parameter. The source code of the ProgrammingParadigm enum looks as follows:

public enum ProgrammingParadigm {

    FUNCTIONAL,
    OBJECT_ORIENTED,
    PROCEDURAL;

    public static ProgrammingParadigm fromProgrammingLanguage(
            ProgrammingLanguage source
    ) {
        return switch(source) {
            case C -> ProgrammingParadigm.PROCEDURAL;
            case CLOJURE -> ProgrammingParadigm.FUNCTIONAL;
            case SMALLTALK -> ProgrammingParadigm.OBJECT_ORIENTED;
        };
    }
}

During this exercise you will create the test data that’s passed to a parameterized test method which ensures that the fromProgrammingLanguage() method of the ProgrammingParadigm enum is working as expected. You can finish this exercise by following these steps:

1. Open the ProgrammingParadigmTest class that’s found from the com.cleantestautomation.junit5intro package.

2. Create the test data that’s passed to the shouldReturnCorrectProgrammingParadigm() method by using the @CsvSource annotation. Remember that your test data must test every possible scenario.

3. Run your parameterized test and make sure that all test invocations pass.