package io.teiler.api.service;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import io.teiler.server.Tylr;
import io.teiler.server.dto.Group;
import io.teiler.server.dto.Person;
import io.teiler.server.services.DebtService;
import io.teiler.server.services.GroupService;
import io.teiler.server.services.PersonService;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Tylr.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(properties = {"local.server.port=4567"})
@ActiveProfiles("test")
public class DebtServiceTest {

    private static final String FIRST_PERSON_NAME = "Johannes";
    private static final String SECOND_PERSON_NAME = "Rudolf";
    private static final String THIRD_PERSON_NAME = "Sepp";
    private static final String TEST_GROUP_NAME = "Testgroup";

    @Autowired
    private DebtService debtService;

    @Autowired
    private PersonService personService;

    @Autowired
    private GroupService groupService;

    @Test
    public void testReturnZeroBalanceWithOnePersonAndNoneTransactions() {
        Group testGroup = groupService.createGroup(TEST_GROUP_NAME);
        String groupId = testGroup.getId();
        Person firstPerson = personService.createPerson(groupId, FIRST_PERSON_NAME);
        debtService.getDebt(groupId);
    }

}

@@ -25,16 +25,108 @@
 rvice;%0A%0A
+import io.teiler.server.dto.*;%0Aimport io.teiler.server.services.*;%0Aimport org.junit.Assert;%0A
 import o
@@ -509,218 +509,59 @@
 lr;%0A
+%0A
 import 
-io.teiler.server.dto.Group;%0Aimport io.teiler.server.dto.Person;%0Aimport io.teiler.server.services.DebtService;%0Aimport io.teiler.server.services.GroupService;%0Aimport io.teiler.server.services.PersonService
+java.util.LinkedList;%0Aimport java.util.List
 ;%0A%0A@
@@ -1139,91 +1139,1583 @@
 ate 
-PersonService personService;%0A%0A    @Autowired%0A    private GroupService groupService;
+ExpenseService expenseService;%0A%0A    @Autowired%0A    private CompensationService compensationService;%0A%0A    @Autowired%0A    private PersonService personService;%0A%0A    @Autowired%0A    private GroupService groupService;%0A%0A    @Test%0A    public void testReturnCorrectBalance() %7B%0A        final Integer SHARE = 5;%0A%0A        Group testGroup = groupService.createGroup(TEST_GROUP_NAME);%0A        String groupId = testGroup.getId();%0A%0A        Person firstPerson = personService.createPerson(groupId, FIRST_PERSON_NAME);%0A        Person secondPerson = personService.createPerson(groupId, SECOND_PERSON_NAME);%0A        Person thirdPerson = personService.createPerson(groupId, THIRD_PERSON_NAME);%0A%0A        List%3CProfiteer%3E firstExpenseProfiteers = new LinkedList%3C%3E();%0A        firstExpenseProfiteers.add(new Profiteer(null, firstPerson, SHARE));%0A        firstExpenseProfiteers.add(new Profiteer(null, secondPerson, SHARE));%0A        firstExpenseProfiteers.add(new Profiteer(null, thirdPerson, SHARE));%0A%0A        Expense firstExpense = new Expense(null, 3 * SHARE, firstPerson, %22Test%22, firstExpenseProfiteers);%0A        expenseService.createExpense(firstExpense, groupId);%0A%0A        System.out.println(firstPerson.getId());%0A        System.out.println(debtService.getDebt(groupId).toString());%0A%0A        for (Debt debt : debtService.getDebt(groupId)) %7B%0A            if (debt.getPerson() == firstPerson.getId()) %7B%0A                Assert.assertEquals(new Integer(10), debt.getBalance());%0A            %7D else %7B%0A                Assert.assertEquals(new Integer(-5), debt.getBalance());%0A            %7D%0A        %7D%0A    %7D
 %0A%0A  
@@ -2905,24 +2905,25 @@
 up.getId();%0A
+%0A
         Pers
@@ -2995,23 +2995,43 @@
 _NAME);%0A
+%0A
        
+ List%3CDebt%3E debts =
  debtSer
@@ -3053,16 +3053,88 @@
 oupId);%0A
+        Assert.assertEquals(new Integer(0), debts.get(0).getBalance());%0A
     %7D%0A%0A%7D

add basic tests