Class BasesConverter

  • All Implemented Interfaces:
    org.junit.jupiter.params.converter.ArgumentConverter

    public class BasesConverter
    extends org.junit.jupiter.params.converter.SimpleArgumentConverter
    Converts String arguments into integers using the base corresponding to their prefix. Uses:
    • 0b for binary (like 0b010010)
    • 0x for hex (like 0xDEADBEEF)
    • none for decimal (like 420)

    Looks prettier than cluttering your tests with parseInt calls everywhere.

    Example:

     @ParameterizedTest(name="a:{0}, b:{1}, sel:00 (a xor b) → out:{2}")
     @CsvSource({
         /*  a      b    |  out */
         "0b1111, 0b0000, 0b1111",
         "0b0000, 0b1111, 0b1111",
         "0b1111, 0b1111, 0b0000",
         "0b1011, 0b0010, 0b1001",
     })
     public void xor(@ConvertWith(BasesConverter.class) int aIn,
                     @ConvertWith(BasesConverter.class) int bIn,
                     @ConvertWith(BasesConverter.class) int outOut) {
         a.set(aIn);
         b.set(bIn);
         sel.set(0b00);
         assertEquals(outOut, out.get(), "out");
     }
     
    See Also:
    The README with examples
    • Constructor Detail

      • BasesConverter

        public BasesConverter()
    • Method Detail

      • convert

        protected Object convert​(Object source,
                                 Class<?> targetType)
        Specified by:
        convert in class org.junit.jupiter.params.converter.SimpleArgumentConverter