EnumExtractor implements Extractor { public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathPart, boolean jsonify) throws AttributeNotFoundException { String pathPart = pPathPart.isEmpty() ? null : pPathPart.pop(); Enum en = (Enum) pValue; String name = en.name(); if (pathPart != null) { if (name.equals(pathPart)) { return name; } else { return pConverter.getValueFaultHandler().handleException( new AttributeNotFoundException("Enum value '" + name + "' doesn't match path '" + pathPart + "'" )); } } return jsonify ? name : en; }  Class getType(); Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathPart, boolean jsonify); Object setObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue); boolean canSetValue();  }
@Test public void jsonExtract() throws AttributeNotFoundException { Stack stack = new Stack(); assertEquals(enumExtractor.extractObject(converter, TestEnum.EINS,stack,true),"EINS"); stack.add("EINS"); assertEquals(enumExtractor.extractObject(converter, TestEnum.EINS,stack,true),"EINS"); }
@Test(expectedExceptions = AttributeNotFoundException.class) public void jsonExtractWithWrongPath() throws AttributeNotFoundException { Stack stack = new Stack(); stack.add("ZWEI"); enumExtractor.extractObject(converter, TestEnum.EINS,stack,true); }
@Test public void plainExtract() throws AttributeNotFoundException { Stack stack = new Stack(); Object result = enumExtractor.extractObject(converter, TestEnum.EINS,stack,false); assertEquals(result,TestEnum.EINS); }