PlanService { public Plan save(PlanDTO planDTO) { Plan plan = GenericConverter.mapper(planDTO, Plan.class); if (plan.isDefaultPlan()) { List<Plan> plans = apiService.plansByApi(plan.getApi().getId()); HeimdallException.checkThrow(plans.stream().anyMatch(Plan::isDefaultPlan), DEFAULT_PLAN_ALREADY_EXIST_TO_THIS_API); } plan = planRepository.save(plan); amqpCacheService.dispatchClean(); return plan; }  @Transactional(readOnly = true) Plan find(Long id); @Transactional(readOnly = true) PlanPage list(PlanDTO planDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Plan> list(PlanDTO planDTO); Plan save(PlanDTO planDTO); Plan update(Long id, PlanDTO planDTO); void delete(Long id);  }
@Test public void saveDefaultPlanWithNullAPI() { thrown.expect(BadRequestException.class); thrown.expectMessage("Api does not exist"); Mockito.when(apiService.plansByApi(1L)) .thenThrow(new BadRequestException(ExceptionMessage.API_NOT_EXIST)); planDTO.setApi(new ReferenceIdDTO(1L)); Plan saved = planService.save(planDTO); }