Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
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
Alex Garcia Alex Garcia
Author Profile Icon Alex Garcia
Alex Garcia
Viktor Farcic Viktor Farcic
Author Profile Icon Viktor Farcic
Viktor Farcic
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Why Should I Care for Test-Driven Development? FREE CHAPTER 2. Tools, Frameworks, and Environments 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 13. Other Books You May Enjoy

Functions revisited


Unlike object-oriented programs, those written in a functional way don't hold any mutable state. Instead, code is made up with functions that take arguments and return values. Because there is no internal state nor side-effects involved that can alter the execution, all functions are deterministic. This is a really good feature because it implies that different executions of the same function, with the same parameters, would produce the same outcome.

The following snippet illustrates a function that does not mutate any internal state:

public Integer add(Integer a, Integer b) {
  return a + b;
}

The following is the same function written using Java's functional API:

public final BinaryOperator<Integer> add =
  new BinaryOperator<Integer>() {

    @Override
    public Integer apply(Integer a, Integer b) {
      return a + b;
    }
  };

The first example should be completely familiar to any Java developer; it follows the common syntax of a function that takes two...

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 $19.99/month. Cancel anytime