Skip to content

Commit 8ccb810

Browse files
committed
Added test suite for item module not provided
1 parent 3a06b41 commit 8ccb810

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

wrappers/bukkit/src/test/java/it/angrybear/yagl/WrappersAdapterTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import org.junit.jupiter.params.provider.EnumSource;
2727
import org.junit.jupiter.params.provider.MethodSource;
2828
import org.mockito.ArgumentCaptor;
29+
import org.mockito.MockedStatic;
2930

3031
import java.lang.reflect.Field;
32+
import java.lang.reflect.Method;
3133
import java.util.ArrayList;
3234
import java.util.Collections;
3335
import java.util.List;
@@ -389,6 +391,21 @@ void testInvalidDataType() {
389391
assertThrowsExactly(IllegalArgumentException.class, () -> WrappersAdapter.convertOption(MockDataType.class, "String"));
390392
}
391393

394+
@Test
395+
void testItemModuleNotProvided() {
396+
try (MockedStatic<WrappersAdapter> clazz = mockStatic(WrappersAdapter.class)) {
397+
clazz.when(() -> {
398+
Method method = WrappersAdapter.class.getDeclaredMethod("getItemUtils");
399+
ReflectionUtils.setAccessible(method).invoke(WrappersAdapter.class);
400+
}).thenReturn(null);
401+
clazz.when(() -> WrappersAdapter.itemToItemStack(any())).thenCallRealMethod();
402+
403+
assertThrowsExactly(IllegalStateException.class, () -> WrappersAdapter.itemToItemStack(null),
404+
"Expected exception to be thrown signaling missing item module, but nothing was thrown");
405+
406+
}
407+
}
408+
392409
private static void initializeBlockData() {
393410
Server server = mock(Server.class);
394411
when(server.createBlockData(any(Material.class), any(String.class))).thenReturn(mock(BlockData.class));

0 commit comments

Comments
 (0)