Share Constants

One of the challenges in getting started arises when constructors set state independent of getters and setters. A typical example of this occurs when constructors use default values, common when you have multiple constructors and simpler ones call more complex ones (Listing 6-4).

Listing 6-4: Use of literal default values in constructor implementations

public class FixedThreadPool {  private final int poolSize;  public FixedThreadPool(int poolSize) {    this.poolSize = poolSize;  }  public FixedThreadPool() {    this(10);  }  public int getPoolSize() {    return poolSize;  }}

Testing the first constructor is trivial. We pass a pool size and use the getter to verify it. We cannot use the getter and ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.