title: j-unit testing Immutable Binary Search Tree add methods
body: <p>I have been attempting to build an immutable binary search tree data structure. Now that I have gotten so far in the development I am attempting to test the methods i have created. So far it is going well.</p>
  
  <p>My add method as it stands:</p>
  
  <pre><code>@Override
  public Set&lt;T&gt; add(T t) {
      if (t.compareTo(x) == 0) {
          return new Add&lt;T&gt;(x, left, right);
      } else {
          if (t.compareTo(x) &lt; 0) {
              return new Add&lt;T&gt;(x, left.add(t), right);
          } else {
              return new Add&lt;T&gt;(x, left, right.add(t));
          }
      }
  }
  </code></pre>
  
  <p>The toString which I think is causing the issue:</p>
  
  <pre><code>@Override
  public String toString(){
      return "";
  }
  </code></pre>
  
  <p>and the unit test:</p>
  
  <pre><code>@Test
  public void SetAddElements(){
      activeSet = newSet.add(1);
      assertEquals("The element(s) were not added!", 1 , activeSet.add(1));
  }
  </code></pre>
  
  <p>However, my .add() method appears to fail my unit test. From what I have deduced the toString method of my Empty class returns white space which means instead of the result of my unit test returning (expected: &lt;1>, ) it returns (expected: &lt;1>, actual: &lt;1 >). A minor difference but enough for the test to fail. </p>
  
  <p><a href="https://i.stack.imgur.com/sa2vL.png" rel="nofollow noreferrer">junit test results and error report</a></p>
  
  <p>I have attempted to remove the toString method but obviously this just returns the default toString and attemoted to research using api and such but came up with nothing. I am struggling to phrase the question in an accurate representation of the problem. Any help would be greatly appreciated.</p>