LinearShape extends Shape { @Override public void calculate() { int numberOfItems = getShapeConfig().getNumberOfElements(); float height = (getShapeConfig().getViewHeight() / 2) - (getShapeConfig().getItemSize() / 2); float itemWidth = getShapeConfig().getItemSize(); float viewMargin = getShapeConfig().getItemMargin(); float x = getFirstItemLeftPosition(); for (int i = 0; i < numberOfItems; i++) { setNoxItemYPosition(i, height); setNoxItemXPosition(i, x); x += itemWidth + viewMargin; } } LinearShape(ShapeConfig shapeConfig); @Override void calculate();  }
@Test public void shouldUseSameTopForEveryElement() { int numberOfElements = 10; ShapeConfig shapeConfig = givenAShapeConfig(numberOfElements, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); float expectedTop = (ANY_VIEW_HEIGHT / 2) - (ANY_ITEM_SIZE / 2); for (int i = 0; i < numberOfElements; i++) { assertEquals(expectedTop, shape.getYForItemAtPosition(i), DELTA); } }
@Test public void shouldCalculateLeftPositionsUsingOneLinearDistributionUsingItemSizeAndMargin() { int numberOfElements = 10; ShapeConfig shapeConfig = givenAShapeConfig(numberOfElements, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); float expectedLeft = ANY_ITEM_MARGIN; for (int i = 0; i < numberOfElements; i++) { assertEquals(expectedLeft, shape.getXForItemAtPosition(i), DELTA); expectedLeft += ANY_ITEM_SIZE + ANY_ITEM_MARGIN; } }
@Test public void shouldCalculateTheCorrectLeftPositionForOneElement() { shape.calculate(); float left = shape.getXForItemAtPosition(0); assertEquals(ANY_ITEM_MARGIN, left, DELTA); }
@Test public void shouldReturnTrueJustForTheElementsInsideTheView() { ShapeConfig shapeConfig = givenAShapeConfig(11, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); assertElementsAtPositionAreInsideTheView(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); assertElementsAtPositionAreOutsizeTheView(10); }