@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forField(propertyName, getRootClass()); throw new NotWritablePropertyException( getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }
@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass()); throw new NotWritablePropertyException(getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }
@Test public void severalMatchesFieldProperty() { PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class); assertThat(matches.getPossibleMatches(), hasItemInArray("counter1")); assertThat(matches.getPossibleMatches(), hasItemInArray("counter2")); assertThat(matches.getPossibleMatches(), hasItemInArray("counter3")); }
@Test public void severalMatchesBeanProperty() { PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class); assertThat(matches.getPossibleMatches(), hasItemInArray("counter1")); assertThat(matches.getPossibleMatches(), hasItemInArray("counter2")); assertThat(matches.getPossibleMatches(), hasItemInArray("counter3")); }
@Test public void complexFieldPropertyTypo() { PropertyMatches matches = PropertyMatches.forField("desriptn", SampleFieldProperties.class); assertThat(matches.getPossibleMatches(), emptyArray()); }
@Test public void simpleBeanPropertyTypo() { PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class); assertThat(matches.getPossibleMatches(), hasItemInArray("name")); }
@Test public void simpleFieldPropertyTypo() { PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class); assertThat(matches.getPossibleMatches(), hasItemInArray("name")); }
@Test public void unknownBeanProperty() { PropertyMatches matches = PropertyMatches.forProperty("unknown", SampleBeanProperties.class); assertThat(matches.getPossibleMatches(), emptyArray()); }
@Test public void unknownFieldProperty() { PropertyMatches matches = PropertyMatches.forField("unknown", SampleFieldProperties.class); assertThat(matches.getPossibleMatches(), emptyArray()); }
@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forField(propertyName, getRootClass()); throw new NotWritablePropertyException( getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }
@Test public void complexBeanPropertyTypo() { PropertyMatches matches = PropertyMatches.forProperty("desriptn", SampleBeanProperties.class); assertThat(matches.getPossibleMatches(), emptyArray()); }
@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass()); throw new NotWritablePropertyException(getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }
throw new NotWritablePropertyException( getRootClass(), this.nestedPath + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches());
private static Set<String> detectPotentialMatches(String propertyName, Class<?> type) { Set<String> result = new HashSet<>(); result.addAll(Arrays.asList(PropertyMatches.forField(propertyName, type).getPossibleMatches())); result.addAll(Arrays.asList(PropertyMatches.forProperty(propertyName, type).getPossibleMatches())); return result; } }
/** * Detects all potential matches for the given property name and type. * * @param propertyName must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return */ private static Set<String> detectPotentialMatches(String propertyName, Class<?> type) { Set<String> result = new HashSet<>(); result.addAll(Arrays.asList(PropertyMatches.forField(propertyName, type).getPossibleMatches())); result.addAll(Arrays.asList(PropertyMatches.forProperty(propertyName, type).getPossibleMatches())); return result; } }
@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass()); throw new NotWritablePropertyException(getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }
@Override protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) { PropertyMatches matches = PropertyMatches.forField(propertyName, getRootClass()); throw new NotWritablePropertyException( getRootClass(), getNestedPath() + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); }