Skip to content

Commit

Permalink
Disallow pane lengths and heights of zero
Browse files Browse the repository at this point in the history
Such panes will not render and allow for hard to find issues in code. Visibility of panes is better controlled via a pane's internal visibility system. Now an error will be thrown when attempting to create a pane with a length or height of zero.
  • Loading branch information
stefvanschie committed Jan 20, 2021
1 parent e805fbd commit 4b387ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public abstract class Pane {
* @param priority the priority of the pane
*/
protected Pane(int x, int y, int length, int height, @NotNull Priority priority) {
if (length == 0 || height == 0) {
throw new IllegalArgumentException("Length and height of pane must be greater than zero");
}

this.x = x;
this.y = y;

Expand All @@ -107,6 +111,10 @@ protected Pane(int x, int y, int length, int height, @NotNull Priority priority)
* @param height the height of the pane
*/
protected Pane(int length, int height) {
if (length == 0 || height == 0) {
throw new IllegalArgumentException("Length and height of pane must be greater than zero");
}

this.length = length;
this.height = height;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void testConstructor() {
void testAddPane() {
InventoryComponent inventoryComponent = new InventoryComponent(0, 0);

inventoryComponent.addPane(new StaticPane(0, 0));
inventoryComponent.addPane(new StaticPane(1, 1));

List<Pane> panes = inventoryComponent.getPanes();

Expand All @@ -33,8 +33,8 @@ void testAddPane() {
void testCopy() {
InventoryComponent original = new InventoryComponent(0, 0);

original.addPane(new StaticPane(0, 0));
original.addPane(new OutlinePane(0, 0));
original.addPane(new StaticPane(1, 1));
original.addPane(new OutlinePane(1, 1));

InventoryComponent copy = original.copy();

Expand All @@ -49,10 +49,10 @@ void testCopy() {
void testExcludeRowsValid() {
InventoryComponent original = new InventoryComponent(0, 6);

original.addPane(new StaticPane(0, 0));
original.addPane(new OutlinePane(0, 0));
original.addPane(new PaginatedPane(0, 0));
original.addPane(new MasonryPane(0, 0));
original.addPane(new StaticPane(1, 1));
original.addPane(new OutlinePane(1, 1));
original.addPane(new PaginatedPane(1, 1));
original.addPane(new MasonryPane(1, 1));

InventoryComponent shrunk = original.excludeRows(4, 4);

Expand Down Expand Up @@ -81,9 +81,9 @@ void testGetPanesEmptyWhenNone() {
void testGetPanesSorted() {
InventoryComponent inventoryComponent = new InventoryComponent(0, 0);

inventoryComponent.addPane(new StaticPane(0, 0, 0, 0, Pane.Priority.HIGHEST));
inventoryComponent.addPane(new OutlinePane(0, 0, 0, 0, Pane.Priority.LOW));
inventoryComponent.addPane(new PaginatedPane(0, 0, 0, 0, Pane.Priority.MONITOR));
inventoryComponent.addPane(new StaticPane(0, 0, 1, 1, Pane.Priority.HIGHEST));
inventoryComponent.addPane(new OutlinePane(0, 0, 1, 1, Pane.Priority.LOW));
inventoryComponent.addPane(new PaginatedPane(0, 0, 1, 1, Pane.Priority.MONITOR));

List<Pane> panes = inventoryComponent.getPanes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public class PaginatedPaneTest {

@Test
void testGetPanesNonExistentPage() {
PaginatedPane pane = new PaginatedPane(0, 0);
PaginatedPane pane = new PaginatedPane(1, 1);

//noinspection ResultOfMethodCallIgnored
assertThrows(IllegalArgumentException.class, () -> pane.getPanes(0));
}

@Test
void testGetPanesCollectionContents() {
PaginatedPane paginatedPane = new PaginatedPane(0, 0);
PaginatedPane paginatedPane = new PaginatedPane(1, 1);

StaticPane pane0 = new StaticPane(0, 0);
StaticPane pane1 = new StaticPane(0, 0);
StaticPane pane2 = new StaticPane(0, 0);
StaticPane pane0 = new StaticPane(1, 1);
StaticPane pane1 = new StaticPane(1, 1);
StaticPane pane2 = new StaticPane(1, 1);

paginatedPane.addPane(0, pane0);
paginatedPane.addPane(0, pane1);
Expand All @@ -39,11 +39,11 @@ void testGetPanesCollectionContents() {

@Test
void testGetPanesCollectionSize() {
PaginatedPane paginatedPane = new PaginatedPane(0, 0);
PaginatedPane paginatedPane = new PaginatedPane(1, 1);

StaticPane pane0 = new StaticPane(0, 0);
StaticPane pane1 = new StaticPane(0, 0);
StaticPane pane2 = new StaticPane(0, 0);
StaticPane pane0 = new StaticPane(1, 1);
StaticPane pane1 = new StaticPane(1, 1);
StaticPane pane2 = new StaticPane(1, 1);

paginatedPane.addPane(0, pane0);
paginatedPane.addPane(0, pane1);
Expand Down

0 comments on commit 4b387ed

Please sign in to comment.