Skip to content

Commit

Permalink
Fix WorkbenchInventoryMock#setMatrix (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorinwasher committed Feb 7, 2024
1 parent 6be1da6 commit b2b0523
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void setResult(@Nullable ItemStack newResult)
@Override
public void setMatrix(@Nullable ItemStack @NotNull [] contents)
{
Preconditions.checkArgument(super.getSize() <= contents.length, "Invalid inventory size. Expected " + super.getSize() + " or less, got " + contents.length);
Preconditions.checkNotNull(contents);
Preconditions.checkArgument(contents.length <= super.getSize(), "Invalid inventory size. Expected " + super.getSize() + " or less, got " + contents.length);
super.setContents(contents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class WorkbenchInventoryMockTest
{
Expand Down Expand Up @@ -61,6 +63,26 @@ void testSetMatrix()
assertArrayEquals(matrix, workbench.getMatrix());
}

@Test
void testSetMatrix_underMaxSize()
{
ItemStack[] matrix = new ItemStack[5];
matrix[4] = new ItemStack(Material.OAK_BOAT);
assertDoesNotThrow(() -> workbench.setMatrix(matrix));
}

@Test
void testSetMatrix_overMaxSize()
{
assertThrows(IllegalArgumentException.class, () -> workbench.setMatrix(new ItemStack[12]));
}

@Test
void testSetMatrix_null()
{
assertThrows(NullPointerException.class, () -> workbench.setMatrix(null));
}

@Test
void testSetMatrix_SetsItems()
{
Expand Down

0 comments on commit b2b0523

Please sign in to comment.