UkelonnServiceProvider extends UkelonnServiceBase { static StringBuilder joinIds(List<Integer> ids) { StringBuilder commaList = new StringBuilder(); if (ids == null) { return commaList; } Iterator<Integer> iterator = ids.iterator(); if (!iterator.hasNext()) { return commaList; } commaList.append(iterator.next()); while(iterator.hasNext()) { commaList.append(", ").append(iterator.next()); } return commaList; }  @Activate void activate(); @Reference(target = "(osgi.jndi.service.name=jdbc/ukelonn)") void setDataSource(DataSource datasource); @Override DataSource getDataSource(); @Reference void setUserAdmin(UserManagementService useradmin); @Reference void setLogservice(LogService logservice); @Override LogService getLogservice(); @Override List<Account> getAccounts(); @Override Account getAccount(String username); @Override Account registerPerformedJob(PerformedTransaction job); @Override List<TransactionType> getJobTypes(); @Override List<Transaction> getJobs(int accountId); @Override List<Transaction> getPayments(int accountId); @Override List<Transaction> deleteJobsFromAccount(int accountId, List<Integer> idsOfJobsToDelete); @Override List<Transaction> updateJob(UpdatedTransaction editedJob); @Override List<TransactionType> getPaymenttypes(); @Override Account registerPayment(PerformedTransaction payment); @Override List<TransactionType> modifyJobtype(TransactionType jobtype); @Override List<TransactionType> createJobtype(TransactionType jobtype); @Override List<TransactionType> modifyPaymenttype(TransactionType paymenttype); @Override List<TransactionType> createPaymenttype(TransactionType paymenttype); @Override Account addAccount(User user); @Override List<SumYear> earningsSumOverYear(String username); @Override List<SumYearMonth> earningsSumOverMonth(String username); @Override List<Notification> notificationsTo(String username); @Override void notificationTo(String username, Notification notification); Account mapAccount(ResultSet results);  }
@Test public void testJoinIds() { assertEquals("", UkelonnServiceProvider.joinIds(null).toString()); assertEquals("", UkelonnServiceProvider.joinIds(Collections.emptyList()).toString()); assertEquals("1", UkelonnServiceProvider.joinIds(Arrays.asList(1)).toString()); assertEquals("1, 2", UkelonnServiceProvider.joinIds(Arrays.asList(1, 2)).toString()); assertEquals("1, 2, 3, 4", UkelonnServiceProvider.joinIds(Arrays.asList(1, 2, 3, 4)).toString()); UserManagementServiceProvider useradmin = mock(UserManagementServiceProvider.class); no.priv.bang.osgiservice.users.User user = new no.priv.bang.osgiservice.users.User(1, "jad", "jad@gmail.com", "Jane", "Doe"); when(useradmin.getUser(anyString())).thenReturn(user); UkelonnServiceProvider ukelonn = getUkelonnServiceSingleton(); ukelonn.setUserAdmin(useradmin); Account account = ukelonn.getAccount("jad"); List<Integer> jobs = ukelonn.getJobs(account.getAccountId()).stream().map(Transaction::getId).collect(Collectors.toList()); assertEquals("31, 33, 34, 35, 37, 38, 39, 41, 42, 43", UkelonnServiceProvider.joinIds(jobs).toString()); }