aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorchill <chill.gtnh@outlook.com>2023-05-27 17:41:53 +0200
committerGitHub <noreply@github.com>2023-05-27 17:41:53 +0200
commitb510ec5baafd4ff69bac158631fc4e4ca93b342d (patch)
treeed356f5d63e2b4c1b384dc4ed6dbda6ff7a35246 /src/test/java
parentd0e291fa8cb31cedcf9ef8fbafb536f19b216907 (diff)
downloadGT5-Unofficial-b510ec5baafd4ff69bac158631fc4e4ca93b342d.tar.gz
GT5-Unofficial-b510ec5baafd4ff69bac158631fc4e4ca93b342d.tar.bz2
GT5-Unofficial-b510ec5baafd4ff69bac158631fc4e4ca93b342d.zip
Refactor checkExoticAndNormalEnergyHatches (#2025)
* add tests to checkExoticAndNormalEnergyHatches Add a parameterized test to GT_MetaTileEntity_MultiBlockBase::checkExoticAndNormalEnergyHatches in order to be sure that the function returns the same results after the change. * refactor checkExoticAndNormalEnergyHatches
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBaseTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBaseTest.java b/src/test/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBaseTest.java
new file mode 100644
index 0000000000..a6f874b956
--- /dev/null
+++ b/src/test/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBaseTest.java
@@ -0,0 +1,46 @@
+package gregtech.api.metatileentity.implementations;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.mockito.Answers;
+import org.mockito.Mockito;
+
+/**
+ * Tests some functions of {@link GT_MetaTileEntity_MultiBlockBase}.
+ * <p>
+ * The classes and tests are non-public because JUnit5
+ * <a href="https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-classes-and-methods">recommends</a>
+ * to omit the {@code public} modifier.
+ */
+@SuppressWarnings("NewClassNamingConvention") /*
+ * The name of the original class does not fit the convention,
+ * but refactoring that is a story for another time.
+ */
+class GT_MetaTileEntity_MultiBlockBaseTest {
+
+ @ParameterizedTest
+ @CsvSource({ "0,0,false", "2,0,false", "1,0,true", "1,1,false", "0,1,true", "0,2,true", "0,3,false" })
+ void checkExoticAndNormalEnergyHatches_parametrizedTest(int exoticEnergyHatchesCount, int normalEnergyHatchesCount,
+ boolean expectedResult) {
+ GT_MetaTileEntity_MultiBlockBase testedClassInstance = Mockito
+ .mock(GT_MetaTileEntity_MultiBlockBase.class, Answers.CALLS_REAL_METHODS);
+
+ testedClassInstance.setEnergyHatches(fillList(GT_MetaTileEntity_Hatch_Energy.class, normalEnergyHatchesCount));
+ testedClassInstance.setExoticEnergyHatches(fillList(GT_MetaTileEntity_Hatch.class, exoticEnergyHatchesCount));
+
+ assertEquals(expectedResult, testedClassInstance.checkExoticAndNormalEnergyHatches());
+ }
+
+ private <T> ArrayList<T> fillList(Class<T> classData, int returnedListSize) {
+ T objectToInsert = Mockito.mock(classData);
+ ArrayList<T> listToReturn = new ArrayList<>();
+ for (int i = 0; i < returnedListSize; i++) {
+ listToReturn.add(objectToInsert);
+ }
+ return listToReturn;
+ }
+}