@Test public void testNewInstance$valid() throws Exception { EnumerationHelper<ValidEnumeration> sut = EnumerationHelper.newInstance(ValidEnumeration.class); assertThat(sut,notNullValue()); assertThat((Object)sut.getEnumeratedClass(),is((Object)ValidEnumeration.class)); assertThat(sut.names(),equalTo(ValidEnumeration.NAMES)); assertThat(sut.name(ValidEnumeration.ONE),equalTo(ValidEnumeration.ONE.name)); assertThat(sut.name(ValidEnumeration.TWO),equalTo(ValidEnumeration.TWO.name)); assertThat(sut.valueOf(ValidEnumeration.ONE.name),equalTo(ValidEnumeration.ONE)); assertThat(sut.valueOf(ValidEnumeration.TWO.name),equalTo(ValidEnumeration.TWO)); assertThat(sut.values(),equalTo(ValidEnumeration.VALUES)); try { sut.valueOf("other"); fail("Invalid names should make the helper fail"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),containsString("'other'")); } }
static <S> EnumerationHelper<S> newInstance(Class<? extends S> clazz) { List<String> violations=new ArrayList<String>(); Set<String> names = getNames(clazz,violations); Method toName=getNameMethod(clazz,violations); Method fromName=getFromURIMethod(clazz,violations); if(!violations.isEmpty()) { throw new InvalidDefinitionException("Violations found: "+violations); } return new EnumerationHelper<S>(names, clazz,toName,fromName); }
EnumerationHelper { static <S> EnumerationHelper<S> newInstance(Class<? extends S> clazz) { List<String> violations=new ArrayList<String>(); Set<String> names = getNames(clazz,violations); Method toName=getNameMethod(clazz,violations); Method fromName=getFromURIMethod(clazz,violations); if(!violations.isEmpty()) { throw new InvalidDefinitionException("Violations found: "+violations); } return new EnumerationHelper<S>(names, clazz,toName,fromName); } }
EnumerationHelper { static <S> EnumerationHelper<S> newInstance(Class<? extends S> clazz) { List<String> violations=new ArrayList<String>(); Set<String> names = getNames(clazz,violations); Method toName=getNameMethod(clazz,violations); Method fromName=getFromURIMethod(clazz,violations); if(!violations.isEmpty()) { throw new InvalidDefinitionException("Violations found: "+violations); } return new EnumerationHelper<S>(names, clazz,toName,fromName); } private  EnumerationHelper(Set<String> names, Class<? extends S> clazz, Method name, Method valueOf); }
EnumerationHelper { static <S> EnumerationHelper<S> newInstance(Class<? extends S> clazz) { List<String> violations=new ArrayList<String>(); Set<String> names = getNames(clazz,violations); Method toName=getNameMethod(clazz,violations); Method fromName=getFromURIMethod(clazz,violations); if(!violations.isEmpty()) { throw new InvalidDefinitionException("Violations found: "+violations); } return new EnumerationHelper<S>(names, clazz,toName,fromName); } private  EnumerationHelper(Set<String> names, Class<? extends S> clazz, Method name, Method valueOf);  }
EnumerationHelper { static <S> EnumerationHelper<S> newInstance(Class<? extends S> clazz) { List<String> violations=new ArrayList<String>(); Set<String> names = getNames(clazz,violations); Method toName=getNameMethod(clazz,violations); Method fromName=getFromURIMethod(clazz,violations); if(!violations.isEmpty()) { throw new InvalidDefinitionException("Violations found: "+violations); } return new EnumerationHelper<S>(names, clazz,toName,fromName); } private  EnumerationHelper(Set<String> names, Class<? extends S> clazz, Method name, Method valueOf);   }