O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required