### Question:
CustomerServiceImpl implements CustomerService { @Override @Transactional(readOnly = true) public void assertDatabaseSize(long customerId) throws LicenseViolationException { CustomerData customerData = getCustomerDataByCustomerId(customerId); int numberOfMethods = countMethods(customerId); doAssertNumberOfMethods(customerData, numberOfMethods); }  @PostConstruct @Transactional void ensurePricePlansExistInDatabase(); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByLicenseKey(@NonNull String licenseKey); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByCustomerId(long customerId); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) List<CustomerData> getCustomerDataByUserEmail(String email); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByExternalId(
      @NonNull String source, @NonNull String externalId); @Override @Transactional(readOnly = true) void assertPublicationSize(CustomerData customerData, int publicationSize); @Override @Transactional(readOnly = true) void assertDatabaseSize(long customerId); @Override @Transactional(readOnly = true) int countMethods(long customerId); @Override @Transactional CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt); @Override @Transactional void registerLogin(LoginRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) AddCustomerResponse addCustomer(AddCustomerRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void changePlanForExternalId(
      String source, @NonNull String externalId, @NonNull String newPlanName); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void deleteCustomerByExternalId(@NonNull String source, String externalId); @Override @Transactional(readOnly = true) @Cacheable(ROLES_CACHE) List<String> getRoleNamesByUserEmail(String email); @Override @Transactional(readOnly = true) @Secured(Roles.ADMIN) List<CustomerData> getCustomerData(); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void updateAppDetails(String appName, String contactEmail, Long customerId);  }### Answer:
@Test public void should_reject_too_many_methods() { when(jdbcTemplate.queryForObject( startsWith("SELECT COUNT(1) FROM methods WHERE"), eq(Long.class), eq(1L))) .thenReturn(50_000L); LicenseViolationException exception = assertThrows(LicenseViolationException.class, () -> service.assertDatabaseSize(1L)); assertThat(exception.getMessage(), containsString("Too many methods")); assertThat(exception.getMessage(), containsString("50000")); verify(eventService).send(any(LicenseViolationEvent.class)); }