feat: Create Job Position Model and Services
Relates to: BAEL-632
This commit is contained in:
parent
aedbf7874c
commit
6b6b7c79b4
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
public class JobPosition {
|
||||
private String title;
|
||||
|
||||
public JobPosition() {}
|
||||
|
||||
public JobPosition(String title) {
|
||||
super();
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface JobService {
|
||||
Optional<JobPosition> findCurrentJobPosition(Person person);
|
||||
|
||||
default boolean assignJobPosition(Person person, JobPosition jobPosition) {
|
||||
if (!findCurrentJobPosition(person).isPresent()) {
|
||||
person.setCurrentJobPosition(jobPosition);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Stream<JobPosition> listJobs(Person person);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private JobPosition currentJobPosition;
|
||||
|
||||
public Person() {}
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public JobPosition getCurrentJobPosition() {
|
||||
return currentJobPosition;
|
||||
}
|
||||
|
||||
public void setCurrentJobPosition(JobPosition currentJobPosition) {
|
||||
this.currentJobPosition = currentJobPosition;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UnemploymentService {
|
||||
|
||||
boolean personIsEntitledToUnemploymentSupport(Person person);
|
||||
|
||||
Optional<JobPosition> searchJob(Person person, String searchString);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class UnemploymentServiceImpl implements UnemploymentService {
|
||||
private final JobService jobService;
|
||||
|
||||
public UnemploymentServiceImpl(JobService jobService) {
|
||||
this.jobService = jobService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean personIsEntitledToUnemploymentSupport(Person person) {
|
||||
Optional<JobPosition> optional = jobService.findCurrentJobPosition(person);
|
||||
|
||||
return !optional.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JobPosition> searchJob(Person person, String searchString) {
|
||||
Stream<JobPosition> stream = jobService.listJobs(person);
|
||||
|
||||
return stream.filter((j) -> j.getTitle().contains(searchString)).findFirst();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue