From 95fcfc4e063f43ef8ecfaa64820a807e42b7aad3 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Fri, 2 Oct 2020 17:18:03 +0200 Subject: [PATCH] Assignments tests --- .../services/AssignmentService.java | 5 ++- .../services/AssignmentServiceTest.java | 35 +++++++++++++++---- .../services/CommisionServiceTest.java | 14 -------- .../plannaplan/services/UserServiceTest.java | 6 ++-- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java b/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java index 734d554..370b545 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java @@ -15,7 +15,6 @@ public class AssignmentService { private AssignmentRepository repo; public AssignmentService() { - super(); } public void save(Assignment assignment) { @@ -25,4 +24,8 @@ public class AssignmentService { public List getCommisionAssignments(Commision com) { return this.repo.getByCommision(com.getId()); } + + public long getAssignmentsAmmount() { + return this.repo.count(); + } } \ No newline at end of file diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java index fe48067..b0dd705 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java @@ -1,12 +1,20 @@ package com.plannaplan.services; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertTrue; +import java.util.List; + +import com.plannaplan.entities.Assignment; +import com.plannaplan.entities.Commision; + +import org.junit.Before; import org.junit.Test; + import org.junit.runner.RunWith; @RunWith(SpringRunner.class) @@ -14,20 +22,35 @@ import org.junit.runner.RunWith; @ContextConfiguration public class AssignmentServiceTest { - // @Autowired - // private AssignmentService service; + @Autowired + private AssignmentService service; + @Autowired + private CommisionService comServie; + private Commision com; - // @Autowired - // private UserService userService; + @Before + public void init() { + this.com = new Commision(); + this.comServie.save(this.com); + } @Test public void shouldSaveAssignment() { - assertTrue("Not implemented", false); + long beginState = this.service.getAssignmentsAmmount(); + this.addAssignmentToCommision(this.com); + assertTrue("Assign ammount should increase", this.service.getAssignmentsAmmount() > beginState); } @Test public void shouldGetCommisionAssignments() { - assertTrue("Not implemented", false); + this.addAssignmentToCommision(this.com); + final List response = this.service.getCommisionAssignments(com); + assertTrue("Returned list size should be 1", response.size() == 1); + } + + private void addAssignmentToCommision(Commision com) { + Assignment a = new Assignment(null, com); + this.service.save(a); } } diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/CommisionServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/CommisionServiceTest.java index dfa5467..3d89613 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/CommisionServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/CommisionServiceTest.java @@ -1,16 +1,11 @@ package com.plannaplan.services; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertTrue; -import com.plannaplan.entities.User; -import com.plannaplan.types.UserRoles; - -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -21,15 +16,6 @@ public class CommisionServiceTest { // @Autowired // private CommisionService service; - @Autowired - private UserService userService; - - @Before - public void initialize() { - User testUser = new User(UserServiceTest.TEST_USER_NAME, UserServiceTest.TEST_USER_SUERNAME, - UserServiceTest.TEST_USER_MAIL, UserRoles.TEST_USER); - this.userService.save(testUser); - } @Test public void shouldSaveCommision() { diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java index b944a7b..f24e0d0 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java @@ -22,9 +22,9 @@ import org.junit.runner.RunWith; @ContextConfiguration @TestMethodOrder(OrderAnnotation.class) public class UserServiceTest { - public static String TEST_USER_MAIL = "noteexisitingmail@notexistingdomain.com"; - public static String TEST_USER_NAME = "Tom"; - public static String TEST_USER_SUERNAME = "Kovalsky"; + private static String TEST_USER_MAIL = "noteexisitingmail@notexistingdomain.com"; + private static String TEST_USER_NAME = "Tom"; + private static String TEST_USER_SUERNAME = "Kovalsky"; @Autowired private UserService userService;