Skip to content

Commit 0211c47

Browse files
committed
Fix unit test
1 parent 176afe3 commit 0211c47

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

src/main/java/org/maxgamer/quickshop/util/Util.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,17 @@ public static List<String> getStartupFlags() {
11631163
* @return under dev-mode
11641164
*/
11651165
public static boolean isDevMode() {
1166-
return devMode != null ? devMode : (devMode = plugin.getConfiguration().getBoolean("dev-mode"));
1166+
if (devMode != null) {
1167+
return devMode;
1168+
} else {
1169+
if (plugin != null) {
1170+
devMode = plugin.getConfiguration().getBoolean("dev-mode");
1171+
return devMode;
1172+
} else {
1173+
return false;
1174+
}
1175+
}
1176+
//F return devMode != null ? devMode : (devMode = plugin.getConfiguration().getBoolean("dev-mode"));
11671177
}
11681178

11691179
/**

src/test/java/org/maxgamer/quickshop/util/InteractUtilTest.java

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,47 @@
1919

2020
package org.maxgamer.quickshop.util;
2121

22+
import de.leonhard.storage.LightningBuilder;
23+
import de.leonhard.storage.Yaml;
24+
import de.leonhard.storage.sections.FlatFileSection;
25+
import org.junit.Assert;
26+
import org.junit.jupiter.api.Test;
27+
28+
import java.io.File;
29+
2230
public class InteractUtilTest {
2331

2432

25-
// private FlatFileSection genConfig(int mode, boolean allowSneaking) {
26-
// FlatFileSection configurationSection = new MemoryConfiguration();
27-
// configurationSection.set("shop.interact.interact-mode", mode);
28-
// configurationSection.set("shop.interact.sneak-to-create", allowSneaking);
29-
// return configurationSection;
30-
// }
31-
//
32-
// @Test
33-
// public void testInteractBoolean() {
34-
// //ONLY
35-
// InteractUtil.init(genConfig(0, true));
36-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
37-
// Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, false));
38-
// InteractUtil.init(genConfig(0, false));
39-
// Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
40-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
41-
// //BOTH
42-
// InteractUtil.init(genConfig(1, false));
43-
// Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
44-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
45-
// InteractUtil.init(genConfig(1, true));
46-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
47-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
48-
// //REVERSED
49-
// InteractUtil.init(genConfig(2, false));
50-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
51-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
52-
// InteractUtil.init(genConfig(2, true));
53-
// Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
54-
// Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
55-
//
56-
// }
33+
private FlatFileSection genConfig(int mode, boolean allowSneaking) {
34+
Yaml configurationSection = LightningBuilder.fromFile(new File("unit-test.yml")).createYaml();
35+
configurationSection.set("shop.interact.interact-mode", mode);
36+
configurationSection.set("shop.interact.sneak-to-create", allowSneaking);
37+
return configurationSection.getSection("");
38+
}
39+
40+
@Test
41+
public void testInteractBoolean() {
42+
//ONLY
43+
InteractUtil.init(genConfig(0, true));
44+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
45+
Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, false));
46+
InteractUtil.init(genConfig(0, false));
47+
Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
48+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
49+
//BOTH
50+
InteractUtil.init(genConfig(1, false));
51+
Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
52+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
53+
InteractUtil.init(genConfig(1, true));
54+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
55+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
56+
//REVERSED
57+
InteractUtil.init(genConfig(2, false));
58+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, true));
59+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
60+
InteractUtil.init(genConfig(2, true));
61+
Assert.assertFalse(InteractUtil.check(InteractUtil.Action.CREATE, true));
62+
Assert.assertTrue(InteractUtil.check(InteractUtil.Action.CREATE, false));
63+
64+
}
5765
}

0 commit comments

Comments
 (0)