|
19 | 19 |
|
20 | 20 | package org.maxgamer.quickshop.util; |
21 | 21 |
|
| 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 | + |
22 | 30 | public class InteractUtilTest { |
23 | 31 |
|
24 | 32 |
|
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 | + } |
57 | 65 | } |
0 commit comments