### Question:
GroupChainGenerator { public GroupChain getGroupChainFor(Collection<Class<?>> groups) { if ( groups == null || groups.size() == 0 ) { throw new IllegalArgumentException( "At least one groups has to be specified." ); } for ( Class<?> clazz : groups ) { if ( !clazz.isInterface() ) { throw new ValidationException( "A groups has to be an interface. " + clazz.getName() + " is not." ); } } GroupChain chain = new GroupChain(); for ( Class<?> clazz : groups ) { if ( clazz.getAnnotation( GroupSequence.class ) == null ) { Group group = new Group( clazz ); chain.insertGroup( group ); insertInheritedGroups( clazz, chain ); } else { insertSequence( clazz, chain ); } } return chain; }  GroupChain getGroupChainFor(Collection<Class<?>> groups);  }### Answer:
@Test(expectedExceptions = ValidationException.class) public void testGroupChainForNonInterface() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add( String.class ); generator.getGroupChainFor( groups ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGroupChainForNull() { generator.getGroupChainFor( null ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGroupChainForEmptySet() { generator.getGroupChainFor( new HashSet<Class<?>>() ); }
@Test(expectedExceptions = ValidationException.class) public void testCyclicGroupSequences() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add( CyclicGroupSequence1.class ); generator.getGroupChainFor( groups ); }
@Test(expectedExceptions = ValidationException.class) public void testCyclicGroupSequence() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add( CyclicGroupSequence.class ); generator.getGroupChainFor( groups ); }
@Test public void testGroupDuplicates() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add( First.class ); groups.add( Second.class ); groups.add( Last.class ); GroupChain chain = generator.getGroupChainFor( groups ); int count = countGroups( chain ); assertEquals( count, 3, "Wrong number of groups" ); groups.clear(); groups.add( First.class ); groups.add( First.class ); chain = generator.getGroupChainFor( groups ); count = countGroups( chain ); assertEquals( count, 1, "Wrong number of groups" ); groups.clear(); groups.add( First.class ); groups.add( Last.class ); groups.add( First.class ); chain = generator.getGroupChainFor( groups ); count = countGroups( chain ); assertEquals( count, 2, "Wrong number of groups" ); }
@Test public void testSequenceResolution() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add( Address.Complete.class ); GroupChain chain = generator.getGroupChainFor( groups ); Iterator<List<Group>> sequences = chain.getSequenceIterator(); List<Group> sequence = sequences.next(); assertEquals( sequence.get( 0 ).getGroup(), Default.class, "Wrong group" ); assertEquals( sequence.get( 1 ).getGroup(), Address.HighLevelCoherence.class, "Wrong group" ); }