Given the following example test classes, one would expect that Test1 and Test2 would share the same ApplicationContext.

However, due to the current implementation of equals() in OverrideMetadata, the annotations on the logically equivalent messageService fields are compared using Arrays.equals() which takes the declaration order into account. Whereas, the declaration order of the annotations is not relevant for this particular "equality" check.

@SpringJUnitConfig(Config.class)
class Test1 {

   @TestBean
   @Qualifier("system")
   MessageService messageService;

   // rest of test class
}
@SpringJUnitConfig(Config.class)
class Test2 {

   @Qualifier("system")
   @TestBean
   MessageService messageService;

   // rest of test class
}

In light of the above, we should compare the annotations declared on a Bean Override field using Set semantics.

FYI: Spring Boot's testing support took the same approach in its QualifierDefinition.