• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/cyclops/integrateddynamics/command/CommandTest.java
1
package org.cyclops.integrateddynamics.command;
2

3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import com.mojang.brigadier.Command;
6
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
7
import com.mojang.brigadier.context.CommandContext;
8
import com.mojang.brigadier.exceptions.CommandSyntaxException;
9
import net.minecraft.commands.CommandSourceStack;
10
import net.minecraft.commands.Commands;
11
import net.minecraft.network.chat.Component;
12
import org.cyclops.integrateddynamics.core.test.IntegrationBefore;
13
import org.cyclops.integrateddynamics.core.test.IntegrationTest;
14

15
import java.lang.reflect.InvocationTargetException;
16
import java.lang.reflect.Method;
17
import java.util.List;
18
import java.util.Map;
19

20
/**
21
 * Command for initiating the integration tests.
22
 * @author rubensworks
23
 *
24
 */
25
public class CommandTest implements Command<CommandSourceStack> {
×
26

27
    public static final String P = "org.cyclops.integrateddynamics.gametest.integration.";
28
    public static final List<String> CLASSES = Lists.newArrayList(
×
29
            P + "TestVariables",
30
            P + "TestBlockOperators",
31
            P + "TestItemStackOperators",
32
            P + "TestEntityOperators",
33
            P + "TestFluidStackOperators",
34
            P + "TestIngredientsOperators",
35
            P + "TestRecipeOperators"
36
    );
37

38
    @Override
39
    public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
40
        context.getSource().getPlayerOrException().sendSystemMessage(Component.literal("Running tests..."));
×
41
        try {
42
            if(!test()) {
×
43
                context.getSource().getPlayerOrException().sendSystemMessage(Component.literal("There were failing tests, see results in console."));
×
44
            } else {
45
                context.getSource().getPlayerOrException().sendSystemMessage(Component.literal("All tests succeeded!"));
×
46
            }
47
            return 0;
×
48
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
×
49
            e.printStackTrace();
×
50
            return 1;
×
51
        }
52
    }
53

54
    protected boolean test() throws IllegalAccessException, InstantiationException, InvocationTargetException {
55
        int ok = 0;
×
56
        int total = 0;
×
57
        for(String className : CLASSES) {
×
58
            try {
59
                Class<?> clazz = Class.forName(className);
×
60
                Object testInstance = clazz.newInstance();
×
61

62
                // Collect test methods
63
                List<Method> befores = Lists.newLinkedList();
×
64
                Map<Method, Boolean> tests = Maps.newHashMap();
×
65
                for (Method method : clazz.getDeclaredMethods()) {
×
66
                    if (method.isAnnotationPresent(IntegrationBefore.class)) {
×
67
                        befores.add(method);
×
68
                    }
69
                    if (method.isAnnotationPresent(IntegrationTest.class)) {
×
70
                        tests.put(method, false);
×
71
                    }
72
                }
73

74
                // Run tests
75
                for (Method test : tests.keySet()) {
×
76
                    String testName = className.replace(P, "") + "#" + test.getName();
×
77
                    for (Method before : befores) {
×
78
                        before.invoke(testInstance);
×
79
                    }
×
80
                    boolean testOk;
81
                    try {
82
                        test.invoke(testInstance);
×
83
                        testOk = true;
×
84
                    } catch (InvocationTargetException e) {
×
85
                        Class<?> excepted = test.getAnnotation(IntegrationTest.class).expected();
×
86
                        if (!excepted.isInstance(e.getTargetException())) {
×
87
                            testOk = false;
×
88
                            if (e.getTargetException() instanceof IllegalStateException || e.getTargetException() instanceof AssertionError) {
×
89
                                System.err.println("Test " + testName + " failed!");
×
90
                                e.getTargetException().printStackTrace();
×
91
                            } else {
92
                                System.err.println(String.format("Expected at %s exception %s, but found:", testName, e));
×
93
                                e.getTargetException().printStackTrace();
×
94
                            }
95
                        } else {
96
                            testOk = true;
×
97
                        }
98
                    }
×
99
                    tests.put(test, testOk);
×
100
                }
×
101

102
                // Count results
103
                for (Boolean result : tests.values()) {
×
104
                    if (result) {
×
105
                        ok++;
×
106
                    }
107
                }
×
108
                total += tests.size();
×
109
            } catch (ClassNotFoundException e) {
×
110
                System.err.println("Skipped test class: " + className);
×
111
            }
×
112
        }
×
113
        System.err.println(String.format("Tests succeeded: %s/%s", ok, total));
×
114
        return ok == total;
×
115
    }
116

117
    public static LiteralArgumentBuilder<CommandSourceStack> make() {
118
        return Commands.literal("test")
×
119
                .requires((commandSource) -> commandSource.hasPermission(2))
×
120
                .executes(new CommandTest());
×
121
    }
122

123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc