title: How to unit test class with no logic?
body: <p>I find it easy to write unit tests for algorithms. For example, <code>sort(List)</code>, it is easy to write tests like:</p>
  
  <pre><code>list = [2, 1, 4];
  assert(sort(list) == [1, 2, 4]);
  </code></pre>
  
  <p>But I find it really hard to test methods that have no logic, no <code>if</code> statements, just a set of calls.</p>
  
  <p>There are mainly 2 examples that I'd like an answer for how to unit test them:</p>
  
  <p><strong>Example 1:</strong></p>
  
  <p>Let's say I have a class that is responsible for writing some data to a file, but that data is written in a specific way by external functions (<code>writeHeaderToFile</code>, <code>writeSerializedData</code> and <code>writeEndOfFile</code>).</p>
  
  <p>The data is not written straight as it is to the file, so if data is something like:</p>
  
  <pre><code>{
      list: [
          "item 1",
          "item 2"
      ],
      name: "aaa"
  }
  </code></pre>
  
  <p>That doesn't mean that the file will be neither the plain version of that data (without white spaces) nor it will be a simple serialized version or encrypted version into file. The actual file binary will be something unknown to me. All I know is that I can use those 3 methods to write in the right way.</p>
  
  <p>This file also contains some other information that doesn't come directly from those 3 methods, like a specific type of header (that again, I have no idea how it will be represented in the file binary).</p>
  
  <p>That is the class:</p>
  
  <pre><code>class FileCreator {
      populateFileWithData(File file, Data data) {
          doBlockWithLock(file, {
              Header header;
              header.format = SomeFormat;
              header.version = SomeVersion;
              writeHeaderToFile(file, header);
  
              writeSerializedData(file, data);
  
              writeEndOfFile(file);
          });
      }
  
      // Private
      void doBlockWithLock(File file, Lambda block) {
          file.holdWritingLock();
          block();
          file.releaseWritingLock();
      }
  }
  </code></pre>
  
  <p><strong>Example 2:</strong></p>
  
  <pre><code>class Controller {
  
      var screenOne = new ScreenOne();
      var screenTwo = new ScreenTwo();
      var screenThree = new ScreenThree();
  
      void reloadButtonWasClicked() {
          screenOne.reload();
          screenTwo.reload();
          screenThree.reload();
      }
  }
  </code></pre>
  
  <p>For this one I could do something like this:</p>
  
  <pre><code>var mockScreenOne = Mock&lt;ScreenOne&gt;().reload.expectOneCall();
  var mockScreenTwo = Mock&lt;ScreenTwo&gt;().reload.expectOneCall();
  var mockScreenThree = Mock&lt;ScreenThree&gt;().reload.expectOneCall();
  
  Controller controller = new Controller();
  controller.screenOne = mockScreenOne;
  controller.screenTwo = mockScreenTwo;
  controller.screenThree = mockScreenThree;
  
  controller.reloadButtonWasClicked();
  
  mockScreenOne.verify();
  mockScreenTwo.verify();
  mockScreenThree.verify();
  </code></pre>
  
  <p>But I don't find much value in it since I'm just asserting that I'm doing the same thing I'm doing in the implementation. Seems like code repetition to me.</p>
  
  <hr>
  
  <p>What would be the proper way of testing my 2 examples?</p>