### Question:
PixelCounter { public int count(Array maskData) { int count = 0; if (maskData != null) { for (int i = 0; i < maskData.getSize(); i++) { final byte value = maskData.getByte(i); if (value != 0) { count++; } } } return count; }  int count(Array maskData);  }### Answer:
@Test public void testCountPixels_all_pixels_valid() throws Exception { final PixelCounter pixelCounter = new PixelCounter(); final Array array = Array.factory(new byte[][]{ {0b0000, 0b0000, 0b0000}, {0b0000, 0b0000, 0b0000}, {0b0000, 0b0000, 0b0000} }); assertEquals(0, pixelCounter.count(array)); }
@Test public void testCountPixels_all_pixels_invalid() throws Exception { final PixelCounter pixelCounter = new PixelCounter(); final Array mask = Array.factory(new byte[][]{ {0b0001, 0b0010, 0b0011}, {0b0100, 0b0101, 0b0110}, {0b0111, 0b1000, 0b1001} }); assertEquals(9, pixelCounter.count(mask)); }
@Test public void testCountPixels_with_null_argument() throws Exception { final PixelCounter pixelCounter = new PixelCounter(); assertEquals(0, pixelCounter.count(null)); }