### Question:
AssuranceServiceImpl implements AssuranceService { @Override public Response create(int typeIndex, String orderId, HttpHeaders headers) { Assurance a = assuranceRepository.findByOrderId(UUID.fromString(orderId)); AssuranceType at = AssuranceType.getTypeByIndex(typeIndex); if (a != null) { AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Fail.Assurance already exists"); return new Response<>(0, "Fail.Assurance already exists", null); } else if (at == null) { AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Fail.Assurance type doesn't exist"); return new Response<>(0, "Fail.Assurance type doesn't exist", null); } else { Assurance assurance = new Assurance(UUID.randomUUID(), UUID.fromString(orderId), at); assuranceRepository.save(assurance); AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Success."); return new Response<>(1, "Success", assurance); } }  @Override Response findAssuranceById(UUID id, HttpHeaders headers); @Override Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers); @Override Response create(int typeIndex, String orderId, HttpHeaders headers); @Override Response deleteById(UUID assuranceId, HttpHeaders headers); @Override Response deleteByOrderId(UUID orderId, HttpHeaders headers); @Override Response modify(String assuranceId, String orderId, int typeIndex, HttpHeaders headers); @Override Response getAllAssurances(HttpHeaders headers); @Override Response getAllAssuranceTypes(HttpHeaders headers);  }### Answer:
@Test public void testCreate1() { UUID orderId = UUID.randomUUID(); Assurance assurance = new Assurance(); Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(assurance); Response result = assuranceServiceImpl.create(0, orderId.toString(), headers); Assert.assertEquals(new Response<>(0, "Fail.Assurance already exists", null), result); }
@Test public void tesCreate2() { UUID orderId = UUID.randomUUID(); Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(null); Response result = assuranceServiceImpl.create(0, orderId.toString(), headers); Assert.assertEquals(new Response<>(0, "Fail.Assurance type doesn't exist", null), result); }
@Test public void testCreate3() { UUID orderId = UUID.randomUUID(); Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(null); Mockito.when(assuranceRepository.save(Mockito.anyCollection())).thenReturn(null); Response result = assuranceServiceImpl.create(1, orderId.toString(), headers); Assert.assertNotNull(result); }