Redefining the default group sequence of a class
2.3.2. Redefining the default group sequence of a class The @GroupSequence annotation also fulfills a second purpose. It allows you to redefine what the Default group means for a given class. To redefine Default for a class, place a @GroupSequence annotation on the class. The defined groups in the annotation express the sequence of groups that substitute Default for this class. Example 2.19, “RentalCar” introduces a new class RentalCar with a redfined default group. With this definition the check for all three groups can be rewritten as seen in Example 2.20, “testOrderedChecksWithRedefinedDefault”. Example 2.19. RentalCar @GroupSequence({ RentalCar.class, CarChecks.class }) public class RentalCar extends Car { public RentalCar(String manufacturer, String licencePlate, int seatCount) { super( manufacturer, licencePlate, seatCount ); } } Example 2.20. testOrderedChecksWithRedefinedDefault @Test public void testOrderedChecksWithRedefinedDefault() { RentalCar rentalCar = new RentalCar( "Morris", "DD-AB-123", 2 ); rentalCar.setPassedVehicleInspection( true ); Driver john = new Driver( "John Doe" ); john.setAge( 18 ); john.passedDrivingTest( true ); rentalCar.setDriver( john ); assertEquals( 0, validator.validate( rentalCar, Default.class, DriverChecks.class ).size() ); } Note Due to the fact that there cannot be a cyclic dependency in the group and group sequence definitions one cannot just add Default to the sequence redefining Default for a class. Instead the class itself should be added!