### Question:
GravityAttributeProcessor extends AttributeProcessor<V> { @Override public Value compile(@Nullable Value value, Context context) { if (null == value) { return NO_GRAVITY; } return ParseHelper.getGravity(value.getAsString()); }  @Override void handleValue(V view, Value value); @Override void handleResource(V view, Resource resource); @Override void handleAttributeResource(V view, AttributeResource attribute); @Override void handleStyleResource(V view, StyleResource style); abstract void setGravity(V view, @Gravity int gravity); @Override Value compile(@Nullable Value value, Context context); static final Primitive NO_GRAVITY; }### Answer:
@Test public void parse_simple() throws Exception { String CENTER = "center"; String CENTER_HORIZONTAL = "center_horizontal"; String CENTER_VERTICAL = "center_vertical"; String LEFT = "left"; String RIGHT = "right"; String TOP = "top"; String BOTTOM = "bottom"; String START = "start"; String END = "end"; Map<String, Integer> sGravityMap = new HashMap<>(); sGravityMap.put(CENTER, Gravity.CENTER); sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); sGravityMap.put(LEFT, Gravity.LEFT); sGravityMap.put(RIGHT, Gravity.RIGHT); sGravityMap.put(TOP, Gravity.TOP); sGravityMap.put(BOTTOM, Gravity.BOTTOM); sGravityMap.put(START, Gravity.START); sGravityMap.put(END, Gravity.END); AttributeProcessor processor = new GravityAttributeProcessor() { @Override public void setGravity(View view, @Gravity int gravity) { } }; for (Map.Entry<String, Integer> entry : sGravityMap.entrySet()) { System.out.print("\nGravityAttributeProcessorTest:parse_simple() when gravity : '" + entry.getKey() + "'\n"); Value value = processor.compile(new Primitive(entry.getKey()), null); assertThat(value.getAsInt(), is(entry.getValue())); } }
@Test public void parse_complex() throws Exception { AttributeProcessor processor = new GravityAttributeProcessor() { @Override public void setGravity(View view, @Gravity int gravity) { } }; Value value = processor.compile(new Primitive("top|left"), null); int gravity = Gravity.TOP | Gravity.LEFT; assertThat(value.getAsInt(), is(gravity)); }