@Test public void canGetMTUsageReportForCurrentUser() { Account account = new Account(); authenticatedAccount.setAuthenticatedAccount(account); DateRange dateRange = DateRange.fromString("2018-05-01..2018-05-30"); List<MTRequestStatistics> stats = ImmutableList.of(new MTRequestStatistics("en", "ja", "https: when(reportingService.getMTRequestStats(account, dateRange)) .thenReturn(stats); Response response = resource.getMachineTranslationUsage( dateRange); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getEntity()).isEqualTo(stats); }
@Override public Response getMachineTranslationUsage(DateRange dateRange) { if (dateRange == null) { throw new InvalidDateParamException("dateRange is required"); } Optional<Account> account = this.authenticatedAccount.getAuthenticatedAccount(); if (!account.isPresent()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } List<MTRequestStatistics> stats = reportingService .getMTRequestStats(account.get(), dateRange); GenericEntity<List<MTRequestStatistics>> entity = new GenericEntity<List<MTRequestStatistics>>(stats) { }; return Response.ok(entity).build(); }
ReportingResourceImpl implements ReportingResource { @Override public Response getMachineTranslationUsage(DateRange dateRange) { if (dateRange == null) { throw new InvalidDateParamException("dateRange is required"); } Optional<Account> account = this.authenticatedAccount.getAuthenticatedAccount(); if (!account.isPresent()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } List<MTRequestStatistics> stats = reportingService .getMTRequestStats(account.get(), dateRange); GenericEntity<List<MTRequestStatistics>> entity = new GenericEntity<List<MTRequestStatistics>>(stats) { }; return Response.ok(entity).build(); } }
ReportingResourceImpl implements ReportingResource { @Override public Response getMachineTranslationUsage(DateRange dateRange) { if (dateRange == null) { throw new InvalidDateParamException("dateRange is required"); } Optional<Account> account = this.authenticatedAccount.getAuthenticatedAccount(); if (!account.isPresent()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } List<MTRequestStatistics> stats = reportingService .getMTRequestStats(account.get(), dateRange); GenericEntity<List<MTRequestStatistics>> entity = new GenericEntity<List<MTRequestStatistics>>(stats) { }; return Response.ok(entity).build(); } ReportingResourceImpl(); @Inject  ReportingResourceImpl(
            ReportingService reportingService,
            AuthenticatedAccount authenticatedAccount); }
ReportingResourceImpl implements ReportingResource { @Override public Response getMachineTranslationUsage(DateRange dateRange) { if (dateRange == null) { throw new InvalidDateParamException("dateRange is required"); } Optional<Account> account = this.authenticatedAccount.getAuthenticatedAccount(); if (!account.isPresent()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } List<MTRequestStatistics> stats = reportingService .getMTRequestStats(account.get(), dateRange); GenericEntity<List<MTRequestStatistics>> entity = new GenericEntity<List<MTRequestStatistics>>(stats) { }; return Response.ok(entity).build(); } ReportingResourceImpl(); @Inject  ReportingResourceImpl(
            ReportingService reportingService,
            AuthenticatedAccount authenticatedAccount); @Override Response getMachineTranslationUsage(DateRange dateRange); }
ReportingResourceImpl implements ReportingResource { @Override public Response getMachineTranslationUsage(DateRange dateRange) { if (dateRange == null) { throw new InvalidDateParamException("dateRange is required"); } Optional<Account> account = this.authenticatedAccount.getAuthenticatedAccount(); if (!account.isPresent()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } List<MTRequestStatistics> stats = reportingService .getMTRequestStats(account.get(), dateRange); GenericEntity<List<MTRequestStatistics>> entity = new GenericEntity<List<MTRequestStatistics>>(stats) { }; return Response.ok(entity).build(); } ReportingResourceImpl(); @Inject  ReportingResourceImpl(
            ReportingService reportingService,
            AuthenticatedAccount authenticatedAccount); @Override Response getMachineTranslationUsage(DateRange dateRange);  }