NamingConventionConverter implements Converter<String, NamingConvention> { @Override public NamingConvention convert(String s) { NamingConvention namingConvention = null; if (s != null) { try { namingConvention = (NamingConvention) NamingConvention.class.getField(s).get(null); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException("Name convention not valid: " + s); } } return namingConvention; }  @Override NamingConvention convert(String s);  }
@Test public void testConvert() { NamingConventionConverter namingConventionConverter = new NamingConventionConverter(); NamingConvention snakeCase = namingConventionConverter.convert("snakeCase"); assertEquals(NamingConvention.snakeCase.getClass().getName(), snakeCase.getClass().getName()); }
@Test public void testConvertNull() { NamingConventionConverter namingConventionConverter = new NamingConventionConverter(); NamingConvention namingConvention = namingConventionConverter.convert(null); assertNull(namingConvention); }
@Test(expected = RuntimeException.class) public void testConvertInvalid() { NamingConventionConverter namingConventionConverter = new NamingConventionConverter(); NamingConvention snakeCase = namingConventionConverter.convert("invalid"); }