1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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 MTEMultiBlockBase}.
* <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) {
MTEMultiBlockBase testedClassInstance = Mockito.mock(MTEMultiBlockBase.class, Answers.CALLS_REAL_METHODS);
testedClassInstance.setEnergyHatches(fillList(MTEHatchEnergy.class, normalEnergyHatchesCount));
testedClassInstance.setExoticEnergyHatches(fillList(MTEHatch.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;
}
}
|