PartFormats { public static PartFormat<String> stringFormat(int version) { PartFormat<String> f = null; for(PartFormat<String> pf : StringFormats.values()) { if(version == pf.getVersion()) f = pf; } InputValidation.begin().when(f == null, "no such string format version " + version).validate(); return f; } private  PartFormats(); static PartFormat<String> stringFormat(int version); static PartFormat<byte[]> bytesFormat(int version); static Part parse(String data); static Part parse(byte[] data); static PartFormat<String> currentStringFormat(); static PartFormat<byte[]> currentBytesFormat();  }
@Test public void testStringVersions() { for(PartFormat<String> pf : StringFormats.values()) { Assert.assertEquals(pf, PartFormats.stringFormat(pf.getVersion())); } try { PartFormats.stringFormat(-1); Assert.fail("invalid part format, no exception"); } catch(IllegalArgumentException e) { } }