AccessTokenService { @Transactional public AccessToken update(Long id, AccessTokenPersist accessTokenPersist) { AccessToken accessToken = accessTokenRepository.findOne(id); HeimdallException.checkThrow(accessToken == null, GLOBAL_RESOURCE_NOT_FOUND); App appRecover = appRespository.findOne(accessTokenPersist.getApp().getId()); HeimdallException.checkThrow(appRecover == null, APP_NOT_EXIST); HeimdallException.checkThrow(!verifyIfPlansContainsInApp(appRecover, accessTokenPersist.getPlans()), SOME_PLAN_NOT_PRESENT_IN_APP); PropertyMap<AccessTokenPersist, AccessToken> propertyMap = new PropertyMap<AccessTokenPersist, AccessToken>() { @Override protected void configure() { skip(destination.getCode()); } }; GenericConverter.convertWithMapping(accessTokenPersist, accessToken, propertyMap); accessToken = accessTokenRepository.save(accessToken); amqpCacheService.dispatchClean(); return accessToken; }  @Transactional(readOnly = true) AccessToken find(Long id); @Transactional(readOnly = true) AccessTokenPage list(AccessTokenRequest accessTokenRequest, PageableDTO pageableDTO); @Transactional(readOnly = true) List<AccessToken> list(AccessTokenRequest accessTokenRequest); @Transactional AccessToken save(AccessTokenPersist accessTokenPersist); @Transactional AccessToken update(Long id, AccessTokenPersist accessTokenPersist); @Transactional void delete(Long id); @Transactional AccessToken save(AccessTokenDTO reqBody);  }
@Test public void notPermitUpdateAnAccessTokenInexistent() { thrown.expect(NotFoundException.class); thrown.expectMessage("Resource not found"); AccessTokenPersist accessTokenPersist = new AccessTokenPersist(); Mockito.when(accessTokenRepository.findOne(Mockito.anyLong())).thenReturn(null); service.update(10L, accessTokenPersist); }
@Test public void notPermitUpdateAnAccessTokenWithInexistentApp() { thrown.expect(BadRequestException.class); thrown.expectMessage("App does not exist"); AccessTokenPersist accessTokenPersist = new AccessTokenPersist(); accessTokenPersist.setApp(new ReferenceIdDTO(10L)); AccessToken recoverAt = new AccessToken(); recoverAt.setCode("123456"); Mockito.when(accessTokenRepository.findOne(Mockito.anyLong())).thenReturn(recoverAt); Mockito.when(appRespository.findOne(Mockito.anyLong())).thenReturn(null); service.update(10L, accessTokenPersist); }