Search in sources :

Example 1 with YAMLNotInitializedException

use of at.pcgamingfreaks.yaml.YAMLNotInitializedException in project Bukkit_Bungee_PluginLib by GeorgH93.

the class ConfigurationTest method testSaveConfigWithError.

@Test(expected = YAMLKeyNotFoundException.class)
public void testSaveConfigWithError() throws Exception {
    YAML mockedYAML = mock(YAML.class);
    doThrow(new YAMLNotInitializedException()).when(mockedYAML).save((File) anyObject());
    Configuration configuration = new Configuration(mockedLogger, new File(System.getProperty("user.dir")), 1);
    configuration.set("NotSavedValue", false);
    Field configurationYAML = Configuration.class.getDeclaredField("config");
    configurationYAML.setAccessible(true);
    YAML currentConfiguration = (YAML) configurationYAML.get(configuration);
    configurationYAML.set(configuration, mockedYAML);
    configuration.saveConfig();
    configurationYAML.set(configuration, currentConfiguration);
    configurationYAML.setAccessible(false);
    configuration.reload();
    configuration.getBool("NotSavedValue");
}
Also used : Field(java.lang.reflect.Field) YAML(at.pcgamingfreaks.yaml.YAML) YAMLNotInitializedException(at.pcgamingfreaks.yaml.YAMLNotInitializedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with YAMLNotInitializedException

use of at.pcgamingfreaks.yaml.YAMLNotInitializedException in project Bukkit_Bungee_PluginLib by GeorgH93.

the class LanguageTest method testSave.

@Test
public void testSave() throws FileNotFoundException, NoSuchFieldException, IllegalAccessException, YAMLNotInitializedException {
    File userDir = new File(System.getProperty("user.dir"));
    Language language = PowerMockito.spy(new Language(mockedLogger, userDir, 1));
    YAML mockedYAML = mock(YAML.class);
    doThrow(new YAMLNotInitializedException()).when(mockedYAML).save(any(File.class));
    Field lang = TestUtils.setAccessible(Language.class, language, "lang", mockedYAML);
    language.save();
    TestUtils.setUnaccessible(lang, language, false);
}
Also used : Field(java.lang.reflect.Field) File(java.io.File) YAML(at.pcgamingfreaks.yaml.YAML) YAMLNotInitializedException(at.pcgamingfreaks.yaml.YAMLNotInitializedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

YAML (at.pcgamingfreaks.yaml.YAML)2 YAMLNotInitializedException (at.pcgamingfreaks.yaml.YAMLNotInitializedException)2 Field (java.lang.reflect.Field)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 File (java.io.File)1