|
| 1 | +/* |
| 2 | + * This file is part of QuickStart Module Loader, licensed under the MIT License (MIT). See the LICENSE.txt file |
| 3 | + * at the root of this project for more details. |
| 4 | + */ |
| 5 | +package uk.co.drnaylor.quickstart.tests.tests; |
| 6 | + |
| 7 | +import com.google.common.collect.Maps; |
| 8 | +import ninja.leaping.configurate.ConfigurationNode; |
| 9 | +import ninja.leaping.configurate.loader.ConfigurationLoader; |
| 10 | +import ninja.leaping.configurate.objectmapping.ObjectMappingException; |
| 11 | +import org.junit.Assert; |
| 12 | +import org.junit.Before; |
| 13 | +import org.junit.Test; |
| 14 | +import uk.co.drnaylor.quickstart.SystemConfig; |
| 15 | +import uk.co.drnaylor.quickstart.config.ModulesConfigAdapter; |
| 16 | +import uk.co.drnaylor.quickstart.enums.LoadingStatus; |
| 17 | +import uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException; |
| 18 | +import uk.co.drnaylor.quickstart.exceptions.NoModuleException; |
| 19 | +import uk.co.drnaylor.quickstart.tests.scaffolding.FakeLoaderTests; |
| 20 | + |
| 21 | +import java.lang.reflect.Constructor; |
| 22 | +import java.util.Map; |
| 23 | + |
| 24 | +public class ModuleConfigurationAdapterTests extends FakeLoaderTests { |
| 25 | + |
| 26 | + private SystemConfig<ConfigurationNode, ConfigurationLoader<ConfigurationNode>> config; |
| 27 | + |
| 28 | + @Before |
| 29 | + @Override |
| 30 | + public void beforeTests() throws Exception { |
| 31 | + super.beforeTests(); |
| 32 | + |
| 33 | + Constructor<?> ctor = SystemConfig.class.getDeclaredConstructors()[0]; |
| 34 | + ctor.setAccessible(true); |
| 35 | + config = (SystemConfig<ConfigurationNode, ConfigurationLoader<ConfigurationNode>>) ctor.newInstance(loader); |
| 36 | + |
| 37 | + Map<String, LoadingStatus> m = Maps.newHashMap(); |
| 38 | + m.put("d", LoadingStatus.DISABLED); |
| 39 | + m.put("e", LoadingStatus.ENABLED); |
| 40 | + m.put("f", LoadingStatus.FORCELOAD); |
| 41 | + config.attachConfigAdapter(ModulesConfigAdapter.modulesKey, new ModulesConfigAdapter(m)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testGettingModulesConfig() throws NoModuleException, IncorrectAdapterTypeException, ObjectMappingException { |
| 46 | + ModulesConfigAdapter mca = config.getConfigAdapterForModule("modules", ModulesConfigAdapter.class); |
| 47 | + Map<String, LoadingStatus> m = mca.getNode(); |
| 48 | + |
| 49 | + Assert.assertEquals(LoadingStatus.DISABLED, m.get("d")); |
| 50 | + Assert.assertEquals(LoadingStatus.ENABLED, m.get("e")); |
| 51 | + Assert.assertEquals(LoadingStatus.FORCELOAD, m.get("f")); |
| 52 | + } |
| 53 | +} |
0 commit comments