Last active
February 15, 2017 10:30
-
-
Save sujeet100/601829b018a3e2cf27760ac136e00639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Scala | |
assert(books.filter((book: Book) => book.author == "Bob") == List(new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200))) | |
//Or | |
assert(books.filter(book => book.author == "Bob") == List(new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200))) | |
//Or | |
assert(books.filter(_.author == "Bob") == List(new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200))) | |
//Java | |
assertThat( | |
books.stream() | |
.filter(book -> book.getAuthor().equals("Bob")) | |
.collect(Collectors.toList()) | |
, is(Arrays.asList( | |
new Book("Clean Code", "Bob", 100), | |
new Book("Extreme Programming", "Bob", 200) | |
))); | |
//Or | |
assertThat(books.stream() | |
.filter((Book book) -> book.getAuthor().equals("Bob")) | |
.collect(Collectors.toList()), | |
is(Arrays.asList( | |
new Book("Clean Code", "Bob", 100), | |
new Book("Extreme Programming", "Bob", 200) | |
))); | |
//Groovy | |
assert books.findAll { Book book -> book.author == "Bob" } == [new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200)] | |
//Or | |
assert books.findAll { book -> book.author == "Bob" } == [new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200)] | |
//Or | |
assert books.findAll { it.author == "Bob" } == [new Book("Clean Code", "Bob", 100), new Book("Extreme Programming", "Bob", 200)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment