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

CyclopsMC / IntegratedDynamics / 16552051255

27 Jul 2025 01:58PM UTC coverage: 53.206% (+8.0%) from 45.161%
16552051255

push

github

rubensworks
Resolve minor TODOs

2888 of 8740 branches covered (33.04%)

Branch coverage included in aggregate %.

17341 of 29280 relevant lines covered (59.22%)

3.08 hits per line

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

40.91
/src/main/java/org/cyclops/integrateddynamics/core/test/TestHelpers.java
1
package org.cyclops.integrateddynamics.core.test;
2

3
import net.minecraft.core.HolderLookup;
4
import net.minecraft.nbt.CompoundTag;
5
import net.minecraft.util.ProblemReporter;
6
import net.minecraft.world.level.storage.TagValueInput;
7
import net.minecraft.world.level.storage.TagValueOutput;
8
import net.minecraft.world.level.storage.ValueInput;
9
import net.minecraft.world.level.storage.ValueOutput;
10
import org.apache.http.util.Asserts;
11
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
12
import org.cyclops.integrateddynamics.command.CommandTest;
13

14
import java.util.Objects;
15
import java.util.function.Consumer;
16
import java.util.function.Function;
17

18
/**
19
 * Helpers for tests
20
 * @author rubensworks
21
 */
22
public class TestHelpers {
×
23

24
    public static boolean canRunIntegrationTests() {
25
        try {
26
            Class.forName(CommandTest.CLASSES.get(0));
×
27
            return true;
×
28
        } catch (ClassNotFoundException e) {
×
29
            return false;
×
30
        }
31
    }
32

33
    /**
34
     * Assertion for equal objects.
35
     * @param actual Actual value.
36
     * @param expected Expected value.
37
     * @param ifEqual Message identifying the assertion.
38
     * @param <T> The type.
39
     */
40
    public static <T> void assertEqual(T actual, T expected, String ifEqual) {
41
        try {
42
            if(actual instanceof Double) {
3✔
43
                Asserts.check(((Double) actual - (Double) expected) < 0.0001D, ifEqual);
15!
44
            } else if(actual instanceof Float) {
3!
45
                Asserts.check(((Float) actual - (Float) expected) < 0.0001F, ifEqual);
×
46
            } else {
47
                Asserts.check(Objects.equals(actual, expected), ifEqual);
5✔
48
            }
49
        } catch (IllegalStateException e) {
×
50
            throw new AssertionError(String.format("Failure: %s. Expected %s, but got %s.", ifEqual, expected, actual));
×
51
        }
1✔
52
    }
1✔
53

54
    /**
55
     * Assertion for non equal objects.
56
     * @param actual Actual value.
57
     * @param expected Expected value.
58
     * @param ifNonEqual Message identifying the assertion.
59
     * @param <T> The type.
60
     */
61
    public static <T> void assertNonEqual(T actual, T expected, String ifNonEqual) {
62
        try {
63
            if(actual instanceof Double) {
3!
64
                Asserts.check(((Double) actual - (Double) expected) >= 0.0001D, ifNonEqual);
×
65
            } else if(actual instanceof Float) {
3!
66
                Asserts.check(((Float) actual - (Float) expected) >= 0.0001F, ifNonEqual);
×
67
            } else {
68
                Asserts.check(!Objects.equals(actual, expected), ifNonEqual);
8!
69
            }
70
        } catch (IllegalStateException e) {
×
71
            throw new AssertionError(String.format("Failure: %s. Expected not %s, but got %s.", ifNonEqual, expected, actual));
×
72
        }
1✔
73
    }
1✔
74

75
    /**
76
     * Assertion for null objects.
77
     * @param actual Actual value.
78
     * @param ifNull Message identifying the assertion.
79
     * @param <T> The type.
80
     */
81
    public static <T> void assertNull(T actual, String ifNull) {
82
        try {
83
            Asserts.check(actual == null, ifNull);
×
84
        } catch (IllegalStateException e) {
×
85
            throw new AssertionError(String.format("Failure: %s. Expected to be null, but got %s.", ifNull, actual));
×
86
        }
×
87
    }
×
88

89
    /**
90
     * Assertion for non null objects.
91
     * @param actual Actual value.
92
     * @param ifNonNull Message identifying the assertion.
93
     * @param <T> The type.
94
     */
95
    public static <T> void assertNonNull(T actual, String ifNonNull) {
96
        try {
97
            Asserts.check(actual != null, ifNonNull);
×
98
        } catch (IllegalStateException e) {
×
99
            throw new AssertionError(String.format("Failure: %s. Expected to be non null, but got %s.", ifNonNull, actual));
×
100
        }
×
101
    }
×
102

103
    public static <T> CompoundTag serialize(Consumer<ValueOutput> deserializer) {
104
        return serialize(deserializer, ValueDeseralizationContext.ofAllEnabled().holderLookupProvider());
5✔
105
    }
106

107
    public static <T> CompoundTag serialize(Consumer<ValueOutput> deserializer, HolderLookup.Provider holderLookup) {
108
        TagValueOutput valueOutput = TagValueOutput.createWithContext(new ProblemReporter() {
9✔
109
            @Override
110
            public ProblemReporter forChild(PathElement p_421613_) {
111
                return this;
2✔
112
            }
113

114
            @Override
115
            public void report(Problem p_422137_) {
116

117
            }
×
118
        }, holderLookup);
119
        deserializer.accept(valueOutput);
3✔
120
        return valueOutput.buildResult();
3✔
121
    }
122

123
    public static <T> T deserialize(CompoundTag tag, Function<ValueInput, T> serializer) {
124
        return deserialize(tag, serializer, ValueDeseralizationContext.ofAllEnabled().holderLookupProvider());
6✔
125
    }
126

127
    public static <T> T deserialize(CompoundTag tag, Function<ValueInput, T> serializer, HolderLookup.Provider holderLookup) {
128
        ValueInput valueInput = TagValueInput.create(new ProblemReporter() {
10✔
129
            @Override
130
            public ProblemReporter forChild(PathElement p_421613_) {
131
                return this;
2✔
132
            }
133

134
            @Override
135
            public void report(Problem p_422137_) {
136

137
            }
×
138
        }, holderLookup, tag);
139
        return serializer.apply(valueInput);
4✔
140
    }
141

142
}
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