FieldDeclarationComparator implements Comparator<Property<T>>, Serializable { @Override public int compare(Property<T> prop1, Property<T> prop2) { if (!fieldRanking.containsKey(prop1.getName())) { throw new ViewRenderException("Field [" + prop1.getName() + "] cannot be found"); } if (!fieldRanking.containsKey(prop2.getName())) { throw new ViewRenderException("Field [" + prop2.getName() + "] cannot be found"); } int prop1Rank = fieldRanking.get(prop1.getName()); int prop2Rank = fieldRanking.get(prop2.getName()); if (prop1Rank < prop2Rank) { return -1; } else if (prop1Rank == prop2Rank) { return 0; } else { return 1; } } FieldDeclarationComparator(Class<T> instanceClazz); @Override int compare(Property<T> prop1, Property<T> prop2);  }
@Test public void compareLessThan() { assertEquals(-1, comparator.compare(property1, property2)); }
@Test public void compareEqualTo() { assertEquals(0, comparator.compare(property1, property1)); }
@Test public void compareGreaterThan() { assertEquals(1, comparator.compare(property2, property1)); }
@Test(expected = ViewRenderException.class) public void unknownProperty1ThrowsException() { comparator.compare(new MockProperty(), property2); }
@Test(expected = ViewRenderException.class) public void unknownProperty2ThrowsException() { comparator.compare(property1, new MockProperty()); }