@Test
public void testUpdateJob() throws Exception {

    try {
        UkelonnServiceProvider ukelonn = getUkelonnServiceSingleton();
        String username = "jad";
        UserManagementService useradmin = mock(UserManagementService.class);
        no.priv.bang.osgiservice.users.User user = new no.priv.bang.osgiservice.users.User(1, username, "jad@gmail.com", "Jane", "Doe");
        when(useradmin.getUser(anyString())).thenReturn(user);
        ukelonn.setUserAdmin(useradmin);
        Account account = ukelonn.getAccount(username);
        Transaction job = ukelonn.getJobs(account.getAccountId()).get(0);
        int jobId = job.getId();
        // Save initial values of the job for comparison later
        Integer originalTransactionTypeId = job.getTransactionType().getId();
        Date originalTransactionTime = job.getTransactionTime();
        double originalTransactionAmount = job.getTransactionAmount();
        // Find a different job type that has a different amount
        TransactionType newJobType = findJobTypeWithDifferentIdAndAmount(ukelonn, originalTransactionTypeId, originalTransactionAmount);
        // Create a new job object with a different jobtype and the same id
        Date now = new Date();
        UpdatedTransaction editedJob = new UpdatedTransaction(jobId, account.getAccountId(), newJobType.getId(), now, newJobType.getTransactionAmount());
        List<Transaction> updatedJobs = ukelonn.updateJob(editedJob);
        Transaction editedJobFromDatabase = updatedJobs.stream().filter(t->t.getId() == job.getId()).collect(Collectors.toList()).get(0);
        assertEquals(editedJob.getTransactionTypeId(), editedJobFromDatabase.getTransactionType().getId().intValue());
        assertThat(editedJobFromDatabase.getTransactionTime().getTime()).isGreaterThan(originalTransactionTime.getTime());
        assertEquals(editedJob.getTransactionAmount(), editedJobFromDatabase.getTransactionAmount(), 0.0);
    } finally {
        restoreTestDatabase();
    }
}