-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Description
If two custom marshalles has the same priority and the classes returned getObjectClass() are assignable to the class of the object being marshalled, the one that should be applied is undefined right now, while it should be the one with the "closer" class in the class hierarchy.
See modified unit test that currenlty fails in the last assert
@Test
void testCustomMarshallers() {
CustomObjectMarshaller personMarshaller = Mockito.spy(CustomObjectMarshaller.class);
Mockito.when(personMarshaller.priority()).thenReturn(1);
Mockito.when(personMarshaller.getObjectClass()).thenReturn(Person.class);
CustomObjectMarshaller employeeMarshaller = Mockito.spy(CustomObjectMarshaller.class);
Mockito.when(employeeMarshaller.priority()).thenReturn(2);
Mockito.when(employeeMarshaller.getObjectClass()).thenReturn(Employee.class);
CustomObjectMarshaller objectMarshaller = Mockito.spy(CustomObjectMarshaller.class);
Mockito.when(objectMarshaller.priority()).thenReturn(1);
Mockito.when(objectMarshaller.getObjectClass()).thenReturn(Object.class);
Object employee = new Employee();
Object student = new Student();
Object person = new Person();
Object other = new byte[2];
List<CustomObjectMarshaller> marshallers =
Stream.of(objectMarshaller, employeeMarshaller, personMarshaller)
.sorted()
.collect(Collectors.toList());
assertThat(marshallers).containsExactly(objectMarshaller, personMarshaller, employeeMarshaller);
assertThat(MarshallingUtils.getCustomMarshaller(marshallers, employee.getClass()))
.isEqualTo(employeeMarshaller);
assertThat(MarshallingUtils.getCustomMarshaller(marshallers, person.getClass()))
.isEqualTo(personMarshaller);
assertThat(MarshallingUtils.getCustomMarshaller(marshallers, other.getClass()))
.isEqualTo(objectMarshaller);
assertThat(MarshallingUtils.getCustomMarshaller(marshallers, student.getClass()))
.isEqualTo(employeeMarshaller);
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels