package no.priv.bang.ukelonn.impl;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import javax.faces.event.ActionEvent;

import org.junit.BeforeClass;
import org.junit.Test;
import org.ops4j.pax.jdbc.derby.impl.DerbyDataSourceFactory;
import org.osgi.service.jdbc.DataSourceFactory;

import no.priv.bang.ukelonn.bundle.test.db.UkelonnDatabaseProvider;

public class UkelonnControllerTest {

    @BeforeClass
    public static void setupFakeOsgiServices() {
        UkelonnServiceProvider ukelonnServiceSingleton = new UkelonnServiceProvider();
        UkelonnDatabaseProvider ukelonnDatabaseProvider = new UkelonnDatabaseProvider();
        DataSourceFactory derbyDataSourceFactory = new DerbyDataSourceFactory();
        ukelonnDatabaseProvider.setDataSourceFactory(derbyDataSourceFactory);
        ukelonnServiceSingleton.setUkelonnDatabase(ukelonnDatabaseProvider.get());
    }

    @Test
    public void testFornavn() {
        UkelonnController ukelonn = new UkelonnController();
        ukelonn.setUsername("jod");
        assertEquals("John", ukelonn.getFornavn());
        ukelonn.setFornavn("Kari");
        assertEquals("Kari", ukelonn.getFornavn());
    }

    @Test
    public void testBalanse() {
        UkelonnController ukelonn = new UkelonnController();
        ukelonn.setUsername("jad");
        assertEquals(Double.valueOf(0), ukelonn.getBalanse());
        ukelonn.setBalanse(Double.valueOf(-1));
        assertEquals(Double.valueOf(-1), ukelonn.getBalanse());
    }

    @Test
    public void testJobs() {
        UkelonnController ukelonn = new UkelonnController();
        ukelonn.setUsername("jad");
        assertEquals(3, ukelonn.getJobs().size());
    }

    @Test
    public void testAddJob() {
        UkelonnController ukelonn = new UkelonnController();
        ukelonn.setUsername("jod");
        assertEquals(Double.valueOf(0), ukelonn.getBalanse());
        assertEquals(2, ukelonn.getJobs().size());
        TransactionType newJobType = ukelonn.getJobTypes().get(0);
        ukelonn.setNewJobType(newJobType);
        ukelonn.setNewJobWages(newJobType.getTransactionAmount());
        ukelonn.registerNewJob(mock(ActionEvent.class));
        assertEquals(Double.valueOf(35), ukelonn.getBalanse());
        assertEquals(3, ukelonn.getJobs().size());
    }
}

@@ -1347,33 +1347,21 @@
 tEquals(
-Double.valueOf(0)
+673.0
 , ukelon
@@ -1366,32 +1366,37 @@
 onn.getBalanse()
+, 0.1
 );%0A        ukelo
@@ -1651,32 +1651,33 @@
   assertEquals(3
+3
 , ukelonn.getJob

Test fixes: change expected values after adding more transactions to the test database.