Checkpoint: ExchangeServiceTest

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-13 14:13:26 +01:00
parent d1641277ac
commit 11469e9314
Signed by: y0rune
GPG Key ID: F204C385F57EB348
2 changed files with 17 additions and 9 deletions

View File

@ -78,7 +78,7 @@ public class ExchangeService {
}
public void performExchange() {
final Set<MatchData> matchData = this.getMatches();
final List<MatchData> matchData = this.getMatches();
final List<Long> performedAssignmentExchanges = new ArrayList<>();
matchData.forEach( m -> {
final Assignment assignmentOne = m.getAssignmentOne();
@ -114,16 +114,17 @@ public class ExchangeService {
});
}
public Set<MatchData> getMatches(){
public List<MatchData> getMatches(){
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
final Exchange exchangeOne = (Exchange) m[0];
final Exchange exchangeTwo = (Exchange) m[1];
return new MatchData(exchangeOne, exchangeTwo);
}).collect(Collectors.toList());
Set<MatchData> filterMatches = new TreeSet<>((m1, m2) -> m1.compare(m2));
filterMatches.addAll(matches);
return filterMatches;
final Set<MatchData> uniqData = new HashSet<>(matches);
final List<MatchData> matchDataListSorted = uniqData.stream().sorted((m1, m2) -> -1 * m1.compare(m2))
.collect(Collectors.toList());
return matchDataListSorted;
}
}

View File

@ -68,7 +68,7 @@ public class ExchangeServiceTest {
this.exchangeService.save(new Exchange(assignmentUser1, group2));
this.exchangeService.save(new Exchange(assignmentUser2, group1));
final Set<MatchData> uniqList = this.exchangeService.getMatches();
final List<MatchData> uniqList = this.exchangeService.getMatches();
assertTrue(uniqList.size() == 1);
}
@ -117,9 +117,13 @@ public class ExchangeServiceTest {
this.exchangeService.performExchange();
user1 = this.userService.getById(user1Id).get();
Thread.sleep(1000);
user2 = this.userService.getById(user2Id).get();
Thread.sleep(1000);
user3 = this.userService.getById(user3Id).get();
Thread.sleep(1000);
user4 = this.userService.getById(user4Id).get();
Thread.sleep(1000);
final List<Long> listGroupsOfUser1 = user1.getStudentRegisteredGrups().stream().map(Groups::getId)
.collect(Collectors.toList());
@ -160,9 +164,13 @@ public class ExchangeServiceTest {
this.assignmentService.callAcceptAlgorythm();
this.exchangeService.save(new Exchange(assignmentUser1, group2));
Thread.sleep(1000);
this.exchangeService.save(new Exchange(assignmentUser2, group1));
Thread.sleep(1000);
this.exchangeService.save(new Exchange(assignmentUser1, group3));
Thread.sleep(1000);
this.exchangeService.save(new Exchange(assignmentUser1, group4));
Thread.sleep(1000);
this.exchangeService.performExchange();
@ -176,8 +184,7 @@ public class ExchangeServiceTest {
assertTrue(listGroupsOfUser1.contains(group2.getId()));
assertTrue(listGroupsOfUser2.contains(group1.getId()));
int size = this.exchangeService.getAllExchanges().size();
assertTrue(this.exchangeService.getAllExchanges().size() == 1);
assertTrue(this.exchangeService.getAllExchanges().size() == 2);
}
@Test