### Question:
GreenDetector extends Detector { @Override public float detect(BufferedImage image) { final int width = image.getWidth(); final int height = image.getHeight(); int count = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float[] hsva = ARGB.toHSVA(image.getRGB(x, y)); if (hsva[2] >= 0.50 && hsva[1] >= 0.15 && hsva[0] > 80 && hsva[0] < 180) { count++; } } } return count/((float) width * height); }  @Override float detect(BufferedImage image);  }### Answer:
@Test public void testGreen() throws Exception { BufferedImage image = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB) { @Override public int getRGB(int x, int y) { return ARGB.toARGB(1f, 0f, 1f, 0f); } }; Assert.assertEquals(1, detector.detect(image), 0.1); }
@Test public void testRed() throws Exception { BufferedImage image = new BufferedImage(5,5, BufferedImage.TYPE_INT_ARGB) { @Override public int getRGB(int x, int y) { return ARGB.toARGB(1f, 1f, 0f, 0f); } }; Assert.assertEquals(0, detector.detect(image), 0.1); }
@Test public void testBlue() throws Exception { BufferedImage image = new BufferedImage(5,5, BufferedImage.TYPE_INT_ARGB) { @Override public int getRGB(int x, int y) { return ARGB.toARGB(1f, 0f, 0f, 1f); } }; Assert.assertEquals(0, detector.detect(image), 0.1); }
@Test public void testBlack() throws Exception { BufferedImage image = new BufferedImage(5,5, BufferedImage.TYPE_INT_ARGB) { @Override public int getRGB(int x, int y) { return ARGB.toARGB(1f, 0f, 0f, 0f); } }; Assert.assertEquals(0, detector.detect(image), 0.1); }
@Test public void testWhite() throws Exception { BufferedImage image = new BufferedImage(5,5, BufferedImage.TYPE_INT_ARGB) { @Override public int getRGB(int x, int y) { return ARGB.toARGB(1f, 1f, 1f, 1f); } }; Assert.assertEquals(0, detector.detect(image), 0.1); }