Exact Verification by Value
Before we proceed further, let’s apply a technique from Chapter 6 to our current topic of dealing with strings. One of the basic techniques was sharing constants. In our example, we showed how to use a constant for a default value in a way that simultaneously clarified the intent of the code and made it more testable. At the risk of stating the obvious, that same technique applies well to string verification—and not just verification of default values.
Let’s look at the example of a web controller that, for reasons of compatibility, needs to translate URL parameters from an older version to a newer one. For brevity, let’s assume that we only need to translate a single parameter and that we have a method in our class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access