FlowerDrawer implements RainbowImage.LoadPictureListener { public void paintFlowerFor(Branch branch) { if (hasFlowersToPaint()) { float flowerSize = getFlowerSize(); float rotation = RainbowMath.random(RainbowMath.QUARTER_PI); rainbowDrawer.tint(WHITE); rainbowDrawer.imageMode(Modes.Draw.CENTER); rainbowDrawer.pushMatrix(); rainbowDrawer.translate(branch.getX(), branch.getY()); rainbowDrawer.rotate(rotation); flipHorizontallyIfLuck(); rainbowDrawer.image(getRandomFlower(), 0, 0, flowerSize, flowerSize); rainbowDrawer.popMatrix(); } } FlowerDrawer(Flower flower, List<RainbowImage> flowerImages, RainbowDrawer rainbowDrawer); static FlowerDrawer newInstance(Flower flower, RainbowDrawer rainbowDrawer); void init(); @Override void onLoadSucceed(RainbowImage imageLoaded); @Override void onLoadFail(); void paintFlowerFor(Branch branch);  }
@Test public void testThatPaintFlowerPerformsImagePaintOnRainbowDrawer() { givenThatHasImages(); Branch branch = givenABranch(); flowerDrawer.paintFlowerFor(branch); verify(rainbowDrawer).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat()); }
@Test public void testThatPaintFlowerPerformsTranslationToBranchLocation() { givenThatHasImages(); Branch branch = givenABranch(); flowerDrawer.paintFlowerFor(branch); verify(rainbowDrawer).translate(branch.getX(), branch.getY()); }
@Test public void testThatPaintFlowerPerformsTranslationBeforePaintingImage() { givenThatHasImages(); Branch branch = givenABranch(); flowerDrawer.paintFlowerFor(branch); InOrder drawingOperation = inOrder(rainbowDrawer); drawingOperation.verify(rainbowDrawer).translate(anyFloat(), anyFloat()); drawingOperation.verify(rainbowDrawer).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat()); }
@Test public void testThatPaintFlowerGetsAFlowerFromList() { givenThatHasImages(); Branch branch = givenABranch(); FlowerDrawer flowerDrawer = new FlowerDrawer(flowerToPaint, loadedImagesMock, rainbowDrawer); flowerDrawer.paintFlowerFor(branch); verify(loadedImagesMock).get(anyInt()); }
@Test public void testThatPaintFlowerForBranchDoesNothingIfHasNoFlowersToPaint() { flowerDrawer.paintFlowerFor(givenABranch()); verify(rainbowDrawer, never()).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat()); }