From b510ec5baafd4ff69bac158631fc4e4ca93b342d Mon Sep 17 00:00:00 2001 From: chill Date: Sat, 27 May 2023 17:41:53 +0200 Subject: 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 --- .../GT_MetaTileEntity_MultiBlockBaseTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBaseTest.java (limited to 'src/test') 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}. + *

+ * The classes and tests are non-public because JUnit5 + * recommends + * 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 ArrayList fillList(Class classData, int returnedListSize) { + T objectToInsert = Mockito.mock(classData); + ArrayList listToReturn = new ArrayList<>(); + for (int i = 0; i < returnedListSize; i++) { + listToReturn.add(objectToInsert); + } + return listToReturn; + } +} -- cgit