Skip to content
Snippets Groups Projects
Commit c73cfb26 authored by Goik Martin's avatar Goik Martin
Browse files

Additional test.

parent 602c0438
No related branches found
No related tags found
No related merge requests found
......@@ -13,12 +13,46 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import de.hdm_stuttgart.mi.javastreams.Student.Sex;
/**
* Testing functional queries.
*/
public class FunctionalTests {
final List<Student> roster = Student.createRoster();
/**
* Order all male students by email and create a list of their respective names
* in that order eliminating possible duplicates:
*
* "Bob", 2, Student.Sex.MALE, "bob@uk.edu"
* "Fred", 2, Student.Sex.MALE, "fred@example.com"
* "George", 4, Student.Sex.MALE, "george@math.edu"
* "Jane", 1, Student.Sex.FEMALE, "jane@kiv.de"
* "Kim", 2, Student.Sex.FEMALE, "wilde@serious.de"
*
* ==> {"Bob", "Fred", "George"}
*
*/
@Test
public void allMaleDistinctNameOrderedByEmail() {
List<String> emails =
roster.
stream().
filter(s -> s.gender == Sex.MALE).
sorted((s1, s2) -> s1.getEmailAddress().compareTo(s2.getEmailAddress())).
map(Student::getName).
distinct().
collect(Collectors.toList());
assertThat(emails,
Matchers.<List<String>> equalTo(
ImmutableList.of("Bob", "Fred", "George")
)
);
}
/**
* Summing students' marks having a German email address:
......@@ -38,7 +72,6 @@ public class FunctionalTests {
);
}
/**
* Group students by sex and collect their respective names:
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment