access modifiers and constructors fix

This commit is contained in:
Filip Izydorczyk 2020-09-25 16:43:24 +02:00
parent ce4a5942d5
commit 44bcc24110
12 changed files with 25 additions and 38 deletions

View File

@ -8,6 +8,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import com.plannaplan.types.UserRoles; import com.plannaplan.types.UserRoles;
//should setter be public? //should setter be public?
@Entity @Entity
public class User { public class User {
@ -24,6 +25,13 @@ public class User {
public 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() { public String getEmail() {
return email; return email;
} }

View File

@ -12,7 +12,7 @@ import com.plannaplan.configutils.*;
public class ConfiguratorService { public class ConfiguratorService {
@Autowired @Autowired
FileToDatabaseMigrator migrator; private FileToDatabaseMigrator migrator;
public ConfiguratorService() { public ConfiguratorService() {
} }

View File

@ -18,7 +18,6 @@ public class UserService {
super(); super();
} }
// this code is more idiomatic to java using java 8 stream API
public String login(String authority) throws UserNotFoundException { public String login(String authority) throws UserNotFoundException {
User user = this.repo.getByAuthority(authority.replace("\n", "").trim()) User user = this.repo.getByAuthority(authority.replace("\n", "").trim())
.orElseThrow(() -> new UserNotFoundException("Can not find user with given authority")); .orElseThrow(() -> new UserNotFoundException("Can not find user with given authority"));
@ -33,14 +32,12 @@ public class UserService {
this.repo.save(user); this.repo.save(user);
} }
// this code is more idiomatic to java
public User getUserByEmail(String email) throws UserNotFoundException { public User getUserByEmail(String email) throws UserNotFoundException {
return this.repo.getByAuthority(email.replace("\n", "").trim()) return this.repo.getByAuthority(email.replace("\n", "").trim())
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority")); .orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
} }
// why is not throwing exception?
public User getByToken(String token) { public User getByToken(String token) {
return this.repo.getByToken(token); return this.repo.getByToken(token);
} }

View File

@ -11,9 +11,9 @@ import org.junit.Test;
public class FileReaderTest { public class FileReaderTest {
@Test @Test
public void shoulReturnNull() { public void shoulReturnNull() {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx"); final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
FileReader r = new FileReader(inputStream); final FileReader r = new FileReader(inputStream);
FileData d = r.read(); final FileData d = r.read();
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0")); assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
assertTrue(d.getKeys().size() == 22); assertTrue(d.getKeys().size() == 22);
assertTrue(d != null); assertTrue(d != null);

View File

@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
public class FileToDatabaseMigratorTest { public class FileToDatabaseMigratorTest {
@Autowired @Autowired
FileToDatabaseMigrator migrator; private FileToDatabaseMigrator migrator;
@Autowired @Autowired
private CourseService courseService; private CourseService courseService;

View File

@ -21,7 +21,7 @@ import org.junit.runner.RunWith;
public class ConfiguratorServiceTest { public class ConfiguratorServiceTest {
@Autowired @Autowired
ConfiguratorService configuratorService; private ConfiguratorService configuratorService;
@Autowired @Autowired
private CourseService courseService; private CourseService courseService;

View File

@ -17,20 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner;
public class CourseServiceTest { public class CourseServiceTest {
@Autowired @Autowired
private CourseService courseService; private CourseService courseService;
@Test @Test
public void createAndDeleteCourse() { public void createAndDeleteCourse() {
Course course; Course course = new Course("Testowy kurs", "TK");
int startAmmount = this.courseService.getCoursesAmmount(); int startAmmount = this.courseService.getCoursesAmmount();
// Create course
course = new Course();
course.setName("Testowy kurs");
course.setSymbol("TK");
courseService.save(course); courseService.save(course);
assertTrue(this.courseService.getCoursesAmmount() > startAmmount); assertTrue(this.courseService.getCoursesAmmount() > startAmmount);
// Delete course
courseService.delete(course); courseService.delete(course);
assertTrue(this.courseService.getCoursesAmmount() == startAmmount); assertTrue(this.courseService.getCoursesAmmount() == startAmmount);
} }

View File

@ -21,16 +21,13 @@ public class GroupServiceTest {
@Test @Test
public void createAndDeleteGroup() { public void createAndDeleteGroup() {
Groups group;
int startAmmount = this.groupService.getGroupsAmmount(); int startAmmount = this.groupService.getGroupsAmmount();
//Create group Groups group = new Groups();
group = new Groups();
group.setRoom("A1"); group.setRoom("A1");
groupService.save(group); groupService.save(group);
assertTrue(this.groupService.getGroupsAmmount() > startAmmount); assertTrue(this.groupService.getGroupsAmmount() > startAmmount);
// Delete course
groupService.delete(group); groupService.delete(group);
assertTrue(this.groupService.getGroupsAmmount() == startAmmount); assertTrue(this.groupService.getGroupsAmmount() == startAmmount);
} }

View File

@ -17,21 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner;
public class LecturerServiceTest { public class LecturerServiceTest {
@Autowired @Autowired
private LecturerService lecturerService; private LecturerService lecturerService;
@Test @Test
public void createAndDeleteLecturer(){ public void createAndDeleteLecturer() {
Lecturer lecturer;
int startAmmount = this.lecturerService.getLecturersAmmount(); int startAmmount = this.lecturerService.getLecturersAmmount();
// Create lecturer Lecturer lecturer = new Lecturer("prof.", "Tomasz", "Kowalski");
lecturer = new Lecturer();
lecturer.setName("Tomasz");
lecturer.setSurname("Kowalski");
lecturer.setTitle("prof.");
lecturerService.save(lecturer); lecturerService.save(lecturer);
assertTrue(this.lecturerService.getLecturersAmmount() > startAmmount); assertTrue(this.lecturerService.getLecturersAmmount() > startAmmount);
// Delete lecturer
lecturerService.delete(lecturer); lecturerService.delete(lecturer);
assertTrue(this.lecturerService.getLecturersAmmount() == startAmmount); assertTrue(this.lecturerService.getLecturersAmmount() == startAmmount);
} }

View File

@ -31,18 +31,14 @@ public class UserServiceTest {
@Before @Before
public void initialize() { public void initialize() {
User testUser = new User(); User testUser = new User(TEST_USER_NAME, TEST_USER_SUERNAME, TEST_USER_MAIL, UserRoles.TEST_USER);
testUser.setEmail(TEST_USER_MAIL);
testUser.setName(TEST_USER_NAME);
testUser.setSurname(TEST_USER_SUERNAME);
testUser.setRole(UserRoles.TEST_USER);
this.userService.save(testUser); this.userService.save(testUser);
} }
@Test @Test
public void shouldReturnToken() { public void shouldReturnToken() {
try { try {
String token = this.userService.login(TEST_USER_MAIL); final String token = this.userService.login(TEST_USER_MAIL);
System.out.println("Returned token: " + token); System.out.println("Returned token: " + token);
assertTrue(token != null); assertTrue(token != null);
assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null); assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null);

View File

@ -28,7 +28,7 @@ public class ConfigController {
@PostMapping("/config") @PostMapping("/config")
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) { public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
try { try {
ConfigData data = new ConfigData(null, null, file.getInputStream()); final ConfigData data = new ConfigData(null, null, file.getInputStream());
this.contrl.config(data); this.contrl.config(data);
return new ResponseEntity<>("Sucess", HttpStatus.OK); return new ResponseEntity<>("Sucess", HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {

View File

@ -12,7 +12,7 @@ public class CasValidatorTest {
public void shouldValidateTicket() { public void shouldValidateTicket() {
// you need to privide fresh ticket to make this test pass that's why it is // you need to privide fresh ticket to make this test pass that's why it is
// marked as ignored // 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"); "ST-572267-cbgKrcJLd0tdCubeLqdW-cas.amu.edu.pl");
try { try {
System.out.println(validator.validate()); System.out.println(validator.validate());
@ -24,7 +24,7 @@ public class CasValidatorTest {
@Test @Test
public void shouldNotValidateTicket() { public void shouldNotValidateTicket() {
CasValidator validator = new CasValidator("http://localhost:3000", "notticket"); final CasValidator validator = new CasValidator("http://localhost:3000", "notticket");
try { try {
assertTrue(validator.validate().trim().equals("")); assertTrue(validator.validate().trim().equals(""));
} catch (CasValidationExcepiton e) { } catch (CasValidationExcepiton e) {