Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. beyondxscratch created this gist Jul 14, 2022.
    16 changes: 16 additions & 0 deletions 8-CsvSourceWithExplicitConverters.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    @ParameterizedTest
    @ValueSource(strings = {"JANUARY", "FEBRUARY", "MARCH"})
    void a_test_with_explicit_conversion(
    @ConvertWith(MonthToNumberConverter.class) int month) {
    assertTrue(month <= 3);
    }

    class MonthToNumberConverter extends SimpleArgumentConverter {

    @Override
    protected Object convert(Object source, Class<?> targetType) {
    Month month = Month.valueOf((String) source);
    return month.getValue();
    }

    }