feat: Create Job Position Model and Services

Relates to: BAEL-632
This commit is contained in:
Felipe Reis 2017-03-01 19:28:56 -03:00
parent aedbf7874c
commit 6b6b7c79b4
5 changed files with 105 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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