TetrisGlass implements Glass { public void drop(Figure figure, int x, int y) { if (isOutside(figure, x, y)) { return; } int availablePosition = findAvailableYPosition(figure, x, y); if (availablePosition >= height) { return; } performDrop(figure, x, availablePosition - figure.getBottom()); removeLines(); } TetrisGlass(int width, int height, GlassEventListener... glassEventListeners); boolean accept(Figure figure, int x, int y); void drop(Figure figure, int x, int y); void empty(); @Override void figureAt(Figure figure, int x, int y); @Override List<Plot> getDroppedPlots(); @Override List<Plot> getCurrentFigurePlots(); boolean isEmpty(); static final int BITS_PER_POINT; }
@Test public void shouldNotifyWhenLineRemoved() { glass.drop(glassWidthFigure, 0, HEIGHT); verify(glassEventListener).linesRemoved(removedLines.capture()); assertEquals(1, removedLines.getValue().intValue()); }
@Test public void shouldNotifyWhenSeveralLinesRemoved() { glass.drop(line9Width, 0, HEIGHT); glass.drop(line9Width, 0, HEIGHT); glass.drop(new TetrisFigure(0, 0, "#", "#"), WIDTH - 1, HEIGHT); verify(glassEventListener).linesRemoved(removedLines.capture()); assertEquals(2, removedLines.getValue().intValue()); }
@Test public void shouldNotifyScoreBoardWhenDropped() { glass.drop(point, 0, HEIGHT); verify(glassEventListener).figureDropped(droppedFigure.capture()); assertSame(point, droppedFigure.getValue()); }
@Test public void shouldNotifyAllListenersScoreBoardWhenDropped() { TetrisGlass glass = new TetrisGlass(WIDTH, HEIGHT, glassEventListener, glassEventListener); glass.drop(point, 0, HEIGHT); verify(glassEventListener, times(2)).figureDropped(droppedFigure.capture()); }
@Test public void shouldNotifyAllListenersScoreBoardWhenLinesRemoved() { TetrisGlass glass = new TetrisGlass(WIDTH, HEIGHT, glassEventListener, glassEventListener); glass.drop(glassWidthFigure, 0, HEIGHT); verify(glassEventListener, times(2)).figureDropped(droppedFigure.capture()); }
@Test public void shouldQuietWhenDropOutOfBounds() { glass.drop(createVerticalFigure(HEIGHT), WIDTH / 2, HEIGHT); try { glass.drop(Figure.Type.I.createNewFigure(), WIDTH / 2, HEIGHT); verify(glassEventListener, times(1)).figureDropped(Matchers.<Figure>any()); } catch (Exception e) { fail("Was exception: " + e); } }