### Question:
OrderSorter { public Set<OrderConstraint> getConstraints(List<Class<?>> classes) { Set<OrderConstraint> result = getConstraintsInternal(classes); if (nextCollector.isPresent()) { result.addAll(nextCollector.get().getConstraintsInternal(classes)); } return result; } OrderSorter();  OrderSorter(OrderSorter nextCollector); Set<OrderConstraint> getConstraints(List<Class<?>> classes); List<String> sort(List<Class<?>> classes);  }### Answer:
@Test public void staticUsage() { OrderSorter orderSorter = new StaticUsageOrderSorter(); Set<OrderConstraint> constraints = orderSorter.getConstraints(Lists.newArrayList(new Class<?>[]{ Parent.class, Client.class })); assertEquals(constraints.size(), 1); assertThat(constraints, containsConstraint(Client.class, Parent.class)); }
@Test public void staticUsageNull() { OrderSorter orderSorter = new StaticUsageOrderSorter(); Set<OrderConstraint> constraints = orderSorter.getConstraints(Lists.newArrayList(new Class<?>[]{ ParentNull.class, Client.class })); assertEquals(0, constraints.size()); }
@Test public void staticUsageSubClass() { OrderSorter orderSorter = new StaticUsageOrderSorter(); Set<OrderConstraint> constraints = orderSorter.getConstraints(Lists.newArrayList(new Class<?>[]{ ParentSubClass.class, Client.class, ClientSubClass.class })); assertEquals(constraints.size(), 1); assertThat(constraints, containsConstraint(ClientSubClass.class, ParentSubClass.class)); }
@Test public void getInheritanceConstraints() { OrderSorter orderSorter = new InheritanceOrderSorter(); Set<OrderConstraint> constraints = orderSorter.getConstraints(Lists.newArrayList(new Class<?>[]{ SubClass.class, SuperClass.class, SuperInterface.class })); assertEquals(2, constraints.size()); assertThat(constraints, containsConstraint(SuperClass.class, SubClass.class)); assertThat(constraints, containsConstraint(SuperInterface.class, SuperClass.class)); }