concept Container in category software development

This is an excerpt from Manning's book Seriously Good Software: Code that works, survives, and wins.
This section describes the desired API for the water containers. At the very least, you’ll build a Container class, endowed with a public constructor that takes no arguments and creates an empty container, and the following three methods:
Listing 4.5. Memory2: method connectTo
public void connectTo(Container other) { if (group==null) { #1 If this is isolated, initializes its group group = new Container[] { this }; } if (other.group==null) { #2 If other is isolated, other.group = new Container[] { other }; initializes its group } if (group == other.group) return; #3 Checks if they’re already connected int size1 = group.length, #4 Computes the new water amount size2 = other.group.length; float amount1 = amount * size1, amount2 = other.amount * size2, newAmount = (amount1 + amount2) / (size1 + size2); Container[] newGroup = new Container[size1 + size2]; #5 Allocates new group int i=0; for (Container a: group) { #6 For each container in 1st group... a.group = newGroup; #7 ... updates its group a.amount = newAmount; #8 ... updates its amount newGroup[i++] = a; #9 ... and appends it to newGroup } for (Container b: other.group) { Does the same for 2nd group b.group = newGroup; b.amount = newAmount; newGroup[i++] = b; } } !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":31},{\"line\":1,\"ch\":33}],[{\"line\":4,\"ch\":47},{\"line\":4,\"ch\":49}],[{\"line\":7,\"ch\":42},{\"line\":7,\"ch\":44}],[{\"line\":9,\"ch\":40},{\"line\":9,\"ch\":42}],[{\"line\":16,\"ch\":61},{\"line\":16,\"ch\":63}],[{\"line\":19,\"ch\":35},{\"line\":19,\"ch\":37}],[{\"line\":20,\"ch\":35},{\"line\":20,\"ch\":37}],[{\"line\":21,\"ch\":35},{\"line\":21,\"ch\":37}],[{\"line\":22,\"ch\":35},{\"line\":22,\"ch\":37}]]"} !@%STYLE%@!
It’s time to go back to our containers. This section is a little different from most of the others because you won’t be developing another version of the Container class, but, rather, a set of tests for its functionalities. Which version of Container are we testing, you may ask? Because we’re using the blackbox approach, we’re not targeting any specific implementation of Container. Instead, we’re targeting its API, as established in chapter 1. A nice consequence is that you’ll be able to run the tests against all implementations from this book that comply with that API, and that’s exactly what you’ll do in section 6.2.4. If you feel the need to have a concrete implementation in mind, just think of Reference.
A common way to improve testability in the presence of dependencies is to employ dependency injection. Simply put, if the class under test creates objects of another type (such as a Container creating a HashSet), the dependency injection scheme suggests having the client pass such objects from the outside.