@Test
  public void testCorrectTilesAreCreated()
      throws NDPReadException, ImageTilingException, IOException {
    ImageInformation info = createImageInformation();

    // setup mocks so we get 2x3 tiles
    when(tilePositions.getTileXPositions()).thenReturn(Arrays.asList(new Long[] {1L, 2L}));
    when(tilePositions.getTileYPositions()).thenReturn(Arrays.asList(new Long[] {5L, 7L, 9L}));
    when(tilePositions.getTileWidthInPixels()).thenReturn(20);
    when(tilePositions.getTileHeightInPixels()).thenReturn(10);

    File outputDirectory = temporaryFolder.newFolder("output");

    when(fileNamer.getOutputFileName("testfile", 1, 1)).thenReturn("x1-y1");
    when(fileNamer.getOutputFileName("testfile", 1, 2)).thenReturn("x1-y2");
    when(fileNamer.getOutputFileName("testfile", 1, 3)).thenReturn("x1-y3");
    when(fileNamer.getOutputFileName("testfile", 2, 1)).thenReturn("x2-y1");
    when(fileNamer.getOutputFileName("testfile", 2, 2)).thenReturn("x2-y2");
    when(fileNamer.getOutputFileName("testfile", 2, 3)).thenReturn("x2-y3");

    byte[] t1Bytes = "1".getBytes();
    byte[] t2Bytes = "2".getBytes();
    byte[] t3Bytes = "3".getBytes();
    byte[] t4Bytes = "4".getBytes();
    byte[] t5Bytes = "5".getBytes();
    byte[] t6Bytes = "6".getBytes();
    when(wrapper.getImageSegment("testfile", 1, 5, 0, 30.0f, 20, 10)).thenReturn(t1Bytes);
    when(wrapper.getImageSegment("testfile", 2, 5, 0, 30.0f, 20, 10)).thenReturn(t2Bytes);
    when(wrapper.getImageSegment("testfile", 1, 7, 0, 30.0f, 20, 10)).thenReturn(t3Bytes);
    when(wrapper.getImageSegment("testfile", 2, 7, 0, 30.0f, 20, 10)).thenReturn(t4Bytes);
    when(wrapper.getImageSegment("testfile", 1, 9, 0, 30.0f, 20, 10)).thenReturn(t5Bytes);
    when(wrapper.getImageSegment("testfile", 2, 9, 0, 30.0f, 20, 10)).thenReturn(t6Bytes);

    splitter.tileImage("testfile", tilePositions, info, 30, outputDirectory, statusUpdater);

    // create inOrder object passing any mocks that need to be verified in order
    InOrder inOrder = inOrder(imageCreator, directoryCreator, wrapper);

    inOrder.verify(directoryCreator).createDirectoryIfNeeded(outputDirectory);
    // they come out ordered y then x as follows
    String outputPath = outputDirectory.getAbsolutePath();
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t1Bytes, 20, 10, "x1-y1", outputPath);
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t2Bytes, 20, 10, "x2-y1", outputPath);
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t3Bytes, 20, 10, "x1-y2", outputPath);
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t4Bytes, 20, 10, "x2-y2", outputPath);
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t5Bytes, 20, 10, "x1-y3", outputPath);
    inOrder.verify(imageCreator).createImageFromNdpiBytes(t6Bytes, 20, 10, "x2-y3", outputPath);
    inOrder.verify(wrapper).cleanUp();
    verifyNoMoreInteractions(imageCreator);
  }
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(fileNamer.getOutputFileName(anyString(), anyInt(), anyInt()))
        .thenReturn(temporaryFolder.getRoot().getAbsolutePath() + "/something.txt");

    splitter = new NdpiFileSplitter(wrapper, imageCreator, fileNamer, directoryCreator);
  }