### Question:
RuleProxy implements InvocationHandler { private int compareTo(final Rule otherRule) throws Exception { int otherPriority = otherRule.getPriority(); int priority = getRulePriority(); if (priority < otherPriority) { return -1; } else if (priority > otherPriority) { return 1; } else { String otherName = otherRule.getName(); String name = getRuleName(); return name.compareTo(otherName); } } private  RuleProxy(final Object target); static Rule asRule(final Object rule); @Override Object invoke(final Object proxy, final Method method, final Object[] args); Object getTarget();  }### Answer:
@Test public void testCompareTo() { @org.jeasy.rules.annotation.Rule class MyComparableRule implements Comparable<MyComparableRule> { int comparisonCriteria; MyComparableRule(int comparisonCriteria) { this.comparisonCriteria = comparisonCriteria; } @Condition public boolean when() { return true; } @Action public void then() { } @Override public int compareTo(MyComparableRule otherRule) { return Integer.compare(comparisonCriteria, otherRule.comparisonCriteria); } } Object rule1 = new MyComparableRule(1); Object rule2 = new MyComparableRule(2); Object rule3 = new MyComparableRule(2); Rule proxy1 = RuleProxy.asRule(rule1); Rule proxy2 = RuleProxy.asRule(rule2); Rule proxy3 = RuleProxy.asRule(rule3); assertEquals(proxy1.compareTo(proxy2),-1); assertEquals(proxy2.compareTo(proxy1),1); assertEquals(proxy2.compareTo(proxy3),0); try { Rules rules = new Rules(); rules.register(rule1, rule2); Rules mixedRules = new Rules(rule3); mixedRules.register(proxy1,proxy2); Rules yetAnotherRulesSet = new Rules(proxy1, proxy2); yetAnotherRulesSet.register(rule3); } catch (Exception exception) { fail("Should not fail with " + exception.getMessage()); } }