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 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;
}

View File

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

View File

@ -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);
}

View File

@ -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);

View File

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

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -28,7 +28,7 @@ public class ConfigController {
@PostMapping("/config")
public ResponseEntity<String> 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) {

View File

@ -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) {