GuidedDecisionTableModellerBoundsHelper { public Bounds getBounds( final Set<GuidedDecisionTableView.Presenter> dtPresenters ) { double minX = BOUNDS_MIN_X; double minY = BOUNDS_MIN_Y; double maxX = BOUNDS_MAX_X; double maxY = BOUNDS_MAX_Y; for ( GuidedDecisionTableView.Presenter dtPresenter : dtPresenters ) { final GuidedDecisionTableView dtView = dtPresenter.getView(); minX = Math.min( dtView.getX() - BOUNDS_PADDING, minX ); minY = Math.min( dtView.getY() - BOUNDS_PADDING, minY ); maxX = Math.max( dtView.getX() + dtView.getWidth() + BOUNDS_PADDING, maxX ); maxY = Math.max( dtView.getY() + dtView.getHeight() + BOUNDS_PADDING, maxY ); } bounds.setX( minX ); bounds.setY( minY ); bounds.setWidth( maxX - minX ); bounds.setHeight( maxY - minY ); return bounds; }  Bounds getBounds( final Set<GuidedDecisionTableView.Presenter> dtPresenters ); static final double BOUNDS_MIN_X; static final double BOUNDS_MAX_X; static final double BOUNDS_MIN_Y; static final double BOUNDS_MAX_Y; static final double BOUNDS_PADDING; }
@Test(expected = NullPointerException.class) public void nullCollection() { helper.getBounds( null ); }
@Test public void emptyCollection() { final Bounds b = helper.getBounds( Collections.<GuidedDecisionTableView.Presenter>emptySet() ); assertEquals( BOUNDS_MIN_X, b.getX(), 0.0 ); assertEquals( BOUNDS_MIN_Y, b.getY(), 0.0 ); assertEquals( BOUNDS_MAX_X - BOUNDS_MIN_X, b.getWidth(), 0.0 ); assertEquals( BOUNDS_MAX_Y - BOUNDS_MIN_Y, b.getHeight(), 0.0 ); }
@Test public void emptyOneDecisionTableWithinMinimumBounds() { final Bounds b = helper.getBounds( new HashSet<GuidedDecisionTableView.Presenter>() {{ add( makeTable( 0, 0, 400, 400 ) ); }} ); assertEquals( BOUNDS_MIN_X, b.getX(), 0.0 ); assertEquals( BOUNDS_MIN_Y, b.getY(), 0.0 ); assertEquals( BOUNDS_MAX_X - BOUNDS_MIN_X, b.getWidth(), 0.0 ); assertEquals( BOUNDS_MAX_Y - BOUNDS_MIN_Y, b.getHeight(), 0.0 ); }
@Test public void multipleDecisionTablesCheckLeftBounds() { final Bounds b = helper.getBounds( new HashSet<GuidedDecisionTableView.Presenter>() {{ add( makeTable( 0, 0, 400, 400 ) ); add( makeTable( -2200, 0, 400, 400 ) ); }} ); final double expectedMinX = -2200 - BOUNDS_PADDING; assertEquals( expectedMinX, b.getX(), 0.0 ); assertEquals( BOUNDS_MIN_Y, b.getY(), 0.0 ); assertEquals( BOUNDS_MAX_X - expectedMinX, b.getWidth(), 0.0 ); assertEquals( BOUNDS_MAX_Y - BOUNDS_MIN_Y, b.getHeight(), 0.0 ); }
@Test public void multipleDecisionTablesCheckRightBounds() { final Bounds b = helper.getBounds( new HashSet<GuidedDecisionTableView.Presenter>() {{ add( makeTable( 0, 0, 400, 400 ) ); add( makeTable( 1800, 0, 400, 400 ) ); }} ); final double expectedMaxX = 1800 + 400 + BOUNDS_PADDING; assertEquals( BOUNDS_MIN_X, b.getX(), 0.0 ); assertEquals( BOUNDS_MIN_Y, b.getY(), 0.0 ); assertEquals( expectedMaxX - BOUNDS_MIN_X, b.getWidth(), 0.0 ); assertEquals( BOUNDS_MAX_Y - BOUNDS_MIN_Y, b.getHeight(), 0.0 ); }
@Test public void multipleDecisionTablesCheckTopBounds() { final Bounds b = helper.getBounds( new HashSet<GuidedDecisionTableView.Presenter>() {{ add( makeTable( 0, 0, 400, 400 ) ); add( makeTable( 0, -2200, 400, 400 ) ); }} ); final double expectedMinY = -2200 - BOUNDS_PADDING; assertEquals( BOUNDS_MIN_X, b.getX(), 0.0 ); assertEquals( expectedMinY, b.getY(), 0.0 ); assertEquals( BOUNDS_MAX_X - BOUNDS_MIN_X, b.getWidth(), 0.0 ); assertEquals( BOUNDS_MAX_Y - expectedMinY, b.getHeight(), 0.0 ); }
@Test public void multipleDecisionTablesCheckBottomBounds() { final Bounds b = helper.getBounds( new HashSet<GuidedDecisionTableView.Presenter>() {{ add( makeTable( 0, 0, 400, 400 ) ); add( makeTable( 0, 1800, 400, 400 ) ); }} ); final double expectedMaxY = 1800 + 400 + BOUNDS_PADDING; assertEquals( BOUNDS_MIN_X, b.getX(), 0.0 ); assertEquals( BOUNDS_MIN_Y, b.getY(), 0.0 ); assertEquals( BOUNDS_MAX_X - BOUNDS_MIN_X, b.getWidth(), 0.0 ); assertEquals( expectedMaxY - BOUNDS_MIN_Y, b.getHeight(), 0.0 ); }