Merge pull request 'CourseServiceTest' (#10) from CourseServiceTest into master

Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/10
This commit is contained in:
filipizydorczyk 2020-09-17 16:24:58 +02:00
commit e91965e9b5
6 changed files with 124 additions and 0 deletions

View File

@ -25,6 +25,10 @@ public class CourseService {
this.repo.save(course);
}
public void delete(Course course){
this.repo.delete(course);
}
public int getCoursesAmmount(){
return (int)this.repo.count();
}

View File

@ -28,6 +28,10 @@ public class GroupService {
this.repo.save(group);
}
public void delete(Groups groups){
this.repo.delete(groups);
}
public int getGroupsAmmount(){
return (int)this.repo.count();
}

View File

@ -19,6 +19,10 @@ public class LecturerService {
repo.save(lecturer);
}
public void delete(Lecturer lecturer) {
repo.delete(lecturer);
}
public int getLecturersAmmount(){
return (int)this.repo.count();
}

View File

@ -0,0 +1,37 @@
package com.plannaplan.services;
import static org.junit.Assert.assertTrue;
import com.plannaplan.entities.Course;
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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class CourseServiceTest {
@Autowired
private CourseService courseService;
@Test
public void createAndDeleteCourse() {
Course course;
int startAmmount = this.courseService.getCoursesAmmount();
// Create course
course = new Course();
course.setName("Testowy kurs");
course.setSymbol("TK");
courseService.save(course);
assertTrue(this.courseService.getCoursesAmmount() > startAmmount);
// Delete course
courseService.delete(course);
assertTrue(this.courseService.getCoursesAmmount() == startAmmount);
}
}

View File

@ -0,0 +1,37 @@
package com.plannaplan.services;
import static org.junit.Assert.assertTrue;
import com.plannaplan.entities.Groups;
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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class GroupServiceTest {
@Autowired
private GroupService groupService;
@Test
public void createAndDeleteGroup() {
Groups group;
int startAmmount = this.groupService.getGroupsAmmount();
//Create group
group = new Groups();
group.setRoom("A1");
groupService.save(group);
assertTrue(this.groupService.getGroupsAmmount() > startAmmount);
// Delete course
groupService.delete(group);
assertTrue(this.groupService.getGroupsAmmount() == startAmmount);
}
}

View File

@ -0,0 +1,38 @@
package com.plannaplan.services;
import static org.junit.Assert.assertTrue;
import com.plannaplan.entities.Lecturer;
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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class LecturerServiceTest {
@Autowired
private LecturerService lecturerService;
@Test
public void createAndDeleteLecturer(){
Lecturer lecturer;
int startAmmount = this.lecturerService.getLecturersAmmount();
// Create lecturer
lecturer = new Lecturer();
lecturer.setName("Tomasz");
lecturer.setSurname("Kowalski");
lecturer.setTitle("prof.");
lecturerService.save(lecturer);
assertTrue(this.lecturerService.getLecturersAmmount() > startAmmount);
// Delete lecturer
lecturerService.delete(lecturer);
assertTrue(this.lecturerService.getLecturersAmmount() == startAmmount);
}
}