Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Test-Driven Java Development, Second Edition

You're reading from   Test-Driven Java Development, Second Edition Invoke TDD principles for end-to-end application development

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788836111
Length 324 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Viktor Farcic Viktor Farcic
Author Profile Icon Viktor Farcic
Viktor Farcic
 Garcia Garcia
Author Profile Icon Garcia
Garcia
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Title Page
Packt Upsell
Contributors
Preface
1. Why Should I Care for Test-Driven Development? 2. Tools, Frameworks, and Environments FREE CHAPTER 3. Red-Green-Refactor – From Failure Through Success until Perfection 4. Unit Testing – Focusing on What You Do and Not on What Has Been Done 5. Design – If It's Not Testable, It's Not Designed Well 6. Mocking – Removing External Dependencies 7. TDD and Functional Programming – A Perfect Match 8. BDD – Working Together with the Whole Team 9. Refactoring Legacy Code – Making It Young Again 10. Feature Toggles – Deploying Partially Done Features to Production 11. Putting It All Together 12. Leverage TDD by Implementing Continuous Delivery 1. Other Books You May Enjoy Index

Streams


One of the top utilities included in Java 8 are Streams. In this chapter we are going to use lambdas in combination with Streams in small code fragments, and create a test to verify them.

To better understand what Streams are, what to do, and what not to do with them, it is highly recommended to read Oracle's Stream pages. A good starting point is https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html.

To cut a long story short, Streams provide a bunch of facilities to deal with long computations that can be executed either in parallel or sequential order. Parallel programming is out of the scope of this book, so the next examples will be sequential only. Furthermore, in order to keep the chapter concise we are going to focus on:

  • filter
  • map
  • flatMap
  • reduce

filter

Let's start with the filter operation. Filters is a function with a self-explanatory name; it filters in/out elements in the stream depending on whether the value satisfies a condition, as shown in the following example...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images