From 44bcc24110395586527af1ce6c6245003d2f41d9 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Fri, 25 Sep 2020 16:43:24 +0200 Subject: [PATCH] access modifiers and constructors fix --- .../src/main/java/com/plannaplan/entities/User.java | 8 ++++++++ .../com/plannaplan/services/ConfiguratorService.java | 2 +- .../java/com/plannaplan/services/UserService.java | 3 --- .../com/plannaplan/configutils/FileReaderTest.java | 6 +++--- .../configutils/FileToDatabaseMigratorTest.java | 2 +- .../plannaplan/services/ConfiguratorServiceTest.java | 2 +- .../com/plannaplan/services/CourseServiceTest.java | 9 ++------- .../com/plannaplan/services/GroupServiceTest.java | 5 +---- .../com/plannaplan/services/LecturerServiceTest.java | 12 +++--------- .../com/plannaplan/services/UserServiceTest.java | 8 ++------ .../com/plannaplan/controllers/ConfigController.java | 2 +- .../com/plannaplan/security/CasValidatorTest.java | 4 ++-- 12 files changed, 25 insertions(+), 38 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java index c08bab3..1ed5cfb 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java @@ -8,6 +8,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import com.plannaplan.types.UserRoles; + //should setter be public? @Entity public class User { @@ -24,6 +25,13 @@ public class User { public User() { } + public User(String name, String surname, String mail, UserRoles role) { + this.name = name; + this.surname = surname; + this.email = mail; + this.role = role; + } + public String getEmail() { return email; } diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java b/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java index 500015a..422a646 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java @@ -12,7 +12,7 @@ import com.plannaplan.configutils.*; public class ConfiguratorService { @Autowired - FileToDatabaseMigrator migrator; + private FileToDatabaseMigrator migrator; public ConfiguratorService() { } diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/UserService.java b/buisnesslogic/src/main/java/com/plannaplan/services/UserService.java index d94e269..d17e148 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/UserService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/UserService.java @@ -18,7 +18,6 @@ public class UserService { super(); } - // this code is more idiomatic to java using java 8 stream API public String login(String authority) throws UserNotFoundException { User user = this.repo.getByAuthority(authority.replace("\n", "").trim()) .orElseThrow(() -> new UserNotFoundException("Can not find user with given authority")); @@ -33,14 +32,12 @@ public class UserService { this.repo.save(user); } - // this code is more idiomatic to java public User getUserByEmail(String email) throws UserNotFoundException { return this.repo.getByAuthority(email.replace("\n", "").trim()) .orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority")); } - // why is not throwing exception? public User getByToken(String token) { return this.repo.getByToken(token); } diff --git a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java index f293f74..e8f63d2 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java @@ -11,9 +11,9 @@ import org.junit.Test; public class FileReaderTest { @Test public void shoulReturnNull() { - InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx"); - FileReader r = new FileReader(inputStream); - FileData d = r.read(); + final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx"); + final FileReader r = new FileReader(inputStream); + final FileData d = r.read(); assertTrue(d.getRows().next().getCell(0).toString().equals("1.0")); assertTrue(d.getKeys().size() == 22); assertTrue(d != null); diff --git a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java index 0129999..c58d224 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; public class FileToDatabaseMigratorTest { @Autowired - FileToDatabaseMigrator migrator; + private FileToDatabaseMigrator migrator; @Autowired private CourseService courseService; diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java index 0b1a2b2..4b925f9 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java @@ -21,7 +21,7 @@ import org.junit.runner.RunWith; public class ConfiguratorServiceTest { @Autowired - ConfiguratorService configuratorService; + private ConfiguratorService configuratorService; @Autowired private CourseService courseService; diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java index 10a609f..265f711 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java @@ -17,20 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner; public class CourseServiceTest { @Autowired private CourseService courseService; - + @Test public void createAndDeleteCourse() { - Course course; + Course course = new Course("Testowy kurs", "TK"); 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); } diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java index c6299cb..254957e 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java @@ -21,16 +21,13 @@ public class GroupServiceTest { @Test public void createAndDeleteGroup() { - Groups group; int startAmmount = this.groupService.getGroupsAmmount(); - //Create group - group = new Groups(); + Groups group = new Groups(); group.setRoom("A1"); groupService.save(group); assertTrue(this.groupService.getGroupsAmmount() > startAmmount); - // Delete course groupService.delete(group); assertTrue(this.groupService.getGroupsAmmount() == startAmmount); } diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java index 203f03f..0e5485f 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java @@ -17,21 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner; public class LecturerServiceTest { @Autowired private LecturerService lecturerService; - + @Test - public void createAndDeleteLecturer(){ - Lecturer lecturer; + public void createAndDeleteLecturer() { int startAmmount = this.lecturerService.getLecturersAmmount(); - // Create lecturer - lecturer = new Lecturer(); - lecturer.setName("Tomasz"); - lecturer.setSurname("Kowalski"); - lecturer.setTitle("prof."); + Lecturer lecturer = new Lecturer("prof.", "Tomasz", "Kowalski"); lecturerService.save(lecturer); assertTrue(this.lecturerService.getLecturersAmmount() > startAmmount); - // Delete lecturer lecturerService.delete(lecturer); assertTrue(this.lecturerService.getLecturersAmmount() == startAmmount); } diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java index 7a764f6..5a85627 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java @@ -31,18 +31,14 @@ public class UserServiceTest { @Before public void initialize() { - User testUser = new User(); - testUser.setEmail(TEST_USER_MAIL); - testUser.setName(TEST_USER_NAME); - testUser.setSurname(TEST_USER_SUERNAME); - testUser.setRole(UserRoles.TEST_USER); + User testUser = new User(TEST_USER_NAME, TEST_USER_SUERNAME, TEST_USER_MAIL, UserRoles.TEST_USER); this.userService.save(testUser); } @Test public void shouldReturnToken() { try { - String token = this.userService.login(TEST_USER_MAIL); + final String token = this.userService.login(TEST_USER_MAIL); System.out.println("Returned token: " + token); assertTrue(token != null); assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null); diff --git a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java index 1ce9aa9..5682e78 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java @@ -28,7 +28,7 @@ public class ConfigController { @PostMapping("/config") public ResponseEntity configApp(@RequestParam("file") MultipartFile file) { try { - ConfigData data = new ConfigData(null, null, file.getInputStream()); + final ConfigData data = new ConfigData(null, null, file.getInputStream()); this.contrl.config(data); return new ResponseEntity<>("Sucess", HttpStatus.OK); } catch (IOException e) { diff --git a/restservice/src/test/java/com/plannaplan/security/CasValidatorTest.java b/restservice/src/test/java/com/plannaplan/security/CasValidatorTest.java index 42a2ba8..9772b08 100755 --- a/restservice/src/test/java/com/plannaplan/security/CasValidatorTest.java +++ b/restservice/src/test/java/com/plannaplan/security/CasValidatorTest.java @@ -12,7 +12,7 @@ public class CasValidatorTest { public void shouldValidateTicket() { // you need to privide fresh ticket to make this test pass that's why it is // marked as ignored - CasValidator validator = new CasValidator("http://localhost:3000", + final CasValidator validator = new CasValidator("http://localhost:3000", "ST-572267-cbgKrcJLd0tdCubeLqdW-cas.amu.edu.pl"); try { System.out.println(validator.validate()); @@ -24,7 +24,7 @@ public class CasValidatorTest { @Test public void shouldNotValidateTicket() { - CasValidator validator = new CasValidator("http://localhost:3000", "notticket"); + final CasValidator validator = new CasValidator("http://localhost:3000", "notticket"); try { assertTrue(validator.validate().trim().equals("")); } catch (CasValidationExcepiton e) {