ScopeService { @Transactional public Scope update(final Long apiId, final Long scopeId, Scope scope) { Api api = apiService.find(apiId); this.find(apiId, scopeId); scope.setApi(api); scope.setId(scopeId); scope = scopeRepository.save(scope); amqpCacheService.dispatchClean(); return scope; }  @Transactional(readOnly = true) Scope find(final Long apiId, final Long scopeId); @Transactional(readOnly = true) ScopePage list(final Long apiId, final ScopeDTO scopeDTO, final PageableDTO pageableDTO); @Transactional(readOnly = true) List<Scope> list(final Long apiId, final ScopeDTO scopeDTO); @Transactional Scope save(final Long apiId, Scope scope); @Transactional void delete(final Long apiId, final Long scopeId); @Transactional Scope update(final Long apiId, final Long scopeId, Scope scope);  }
@Test public void updateTest() { Mockito.when(apiService.find(Mockito.anyLong())).thenReturn(scope.getApi()); Mockito.when(scopeRepository.findByApiIdAndId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(scope); scope.setName("Scope new name"); Mockito.when(scopeRepository.save(scope)).thenReturn(scope); Scope updated = scopeService.update(scope.getApi().getId(), scope.getId(), scope); assertEquals(scope.getName(), updated.getName()); }