I have a method thart creates a Specification from a user role. I am trying to create a junit test to see if the output is well created.
In this example I am providing, the user with an IP role, and the specification resulted should only contain a check of its process name.
@InjectMocks
private CbdAccessServiceBusiness cbdAccessServiceBusiness;
@Mock
private MyUser myUser;
@Test
void when_user_is_ip_then_returns_specification_with_only_its_industrial_process() {
// Given
IndustrialProcessEntity ip = randomlyGenerateOne(IndustrialProcessEntity.class);
when(myUser.getRole()).thenReturn(IP);
when(myUser.getIndustrialProcess()).thenReturn(ip);
// When
Specification<CbdEntity> spec = cbdAccessServiceBusiness.deductSpecificationsFromUserRights();
// Then
Specification<CbdEntity> expectedSpec = CbdSpecifications.processIn(List.of(ip.getName()));
assertEquals(expectedSpec, spec);
}
Thought the assertEquals
can’t work as two instances of specification are created. WHat I would like to be able is to compare the content of both specification.