UkelonnServiceProvider extends UkelonnServiceBase { @Override public Account addAccount(User user) { String username = user.getUsername(); try(Connection connection = datasource.getConnection()) { try(PreparedStatement insertAccountSql = connection.prepareStatement("insert into accounts (username) values (?)")) { insertAccountSql.setString(1, username); insertAccountSql.executeUpdate(); } addDummyPaymentToAccountSoThatAccountWillAppearInAccountsView(username); return getAccount(user.getUsername()); } catch (SQLException e) { String message = "Database exception when account for new user"; logservice.log(LogService.LOG_ERROR, message, e); throw new UkelonnException(message, e); } }  @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 testAddAccount() { UkelonnServiceProvider ukelonn = getUkelonnServiceSingleton(); UserManagementServiceProvider usermanagement = new UserManagementServiceProvider(); usermanagement.setLogservice(ukelonn.getLogservice()); usermanagement.setDataSource(ukelonn.getDataSource()); ukelonn.setUserAdmin(usermanagement); String newUsername = "aragorn"; String newEmailaddress = "strider@hotmail.com"; String newFirstname = "Aragorn"; String newLastname = "McArathorn"; no.priv.bang.osgiservice.users.User user = new no.priv.bang.osgiservice.users.User(0, newUsername, newEmailaddress, newFirstname, newLastname); UserAndPasswords passwords = new UserAndPasswords(user, "zecret", "zecret", false); List<no.priv.bang.osgiservice.users.User> updatedUsers = usermanagement.addUser(passwords); no.priv.bang.osgiservice.users.User createdUser = updatedUsers.stream().filter(u -> newUsername.equals(u.getUsername())).findFirst().get(); User userWithUserId = new User(createdUser.getUserid(), newUsername, newEmailaddress, newFirstname, newLastname); Account newAccount = ukelonn.addAccount(userWithUserId); assertThat(newAccount.getAccountId()).isPositive(); assertEquals(0.0, newAccount.getBalance(), 0); }