Polishing

This commit is contained in:
Sam Brannen 2024-05-01 16:04:10 +03:00
parent 37dd47c6fc
commit 4e6591e1a9
1 changed files with 6 additions and 28 deletions

View File

@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import com.fasterxml.jackson.databind.JsonNode;
@ -731,7 +732,7 @@ class IndexingTests {
.isThrownBy(() -> propertyExpression.getValue(context, birdNameMappings))
.withMessageEndingWith("A problem occurred while attempting to read index '%s' in '%s'",
"property", BirdNameToColorMappings.class.getName())
.havingCause().withMessage("unknown bird color: property");
.havingCause().withMessage("unknown bird: property");
}
static class BirdNameToColorMappings {
@ -742,38 +743,15 @@ class IndexingTests {
return switch (name) {
case "cardinal" -> Color.RED;
case "blue jay" -> Color.BLUE;
default -> throw new RuntimeException("unknown bird color: " + name);
default -> throw new NoSuchElementException("unknown bird: " + name);
};
}
}
static class BirdNameToColorMappingsIndexAccessor implements IndexAccessor {
static class BirdNameToColorMappingsIndexAccessor extends ReflectiveIndexAccessor {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class<?>[] { BirdNameToColorMappings.class };
}
@Override
public boolean canRead(EvaluationContext context, Object target, Object index) {
return (target instanceof BirdNameToColorMappings && index instanceof String);
}
@Override
public TypedValue read(EvaluationContext context, Object target, Object index) {
BirdNameToColorMappings mappings = (BirdNameToColorMappings) target;
String name = (String) index;
return new TypedValue(mappings.get(name));
}
@Override
public boolean canWrite(EvaluationContext context, Object target, Object index) {
return false;
}
@Override
public void write(EvaluationContext context, Object target, Object index, @Nullable Object newValue) {
throw new UnsupportedOperationException();
BirdNameToColorMappingsIndexAccessor() {
super(BirdNameToColorMappings.class, String.class, "get");
}
}