53 lines
1.7 KiB
Java
53 lines
1.7 KiB
Java
package games.dmg.spigotquestboard;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Path;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
final class PlayerCommandSettingsTest {
|
|
@TempDir Path temporaryDirectory;
|
|
|
|
@Test
|
|
void defaultsDisabledAndPersistsEnabledState() throws Exception {
|
|
Path path = temporaryDirectory.resolve("settings.yml");
|
|
PlayerCommandSettings settings = new PlayerCommandSettings(
|
|
new YamlPlayerCommandSettingsRepository(path)
|
|
);
|
|
|
|
assertFalse(settings.enabled());
|
|
settings.setEnabled(true);
|
|
|
|
PlayerCommandSettings reloaded = new PlayerCommandSettings(
|
|
new YamlPlayerCommandSettingsRepository(path)
|
|
);
|
|
assertTrue(reloaded.enabled());
|
|
|
|
reloaded.setEnabled(false);
|
|
|
|
assertFalse(new PlayerCommandSettings(
|
|
new YamlPlayerCommandSettingsRepository(path)
|
|
).enabled());
|
|
}
|
|
|
|
@Test
|
|
void persistenceFailureLeavesPriorState() throws Exception {
|
|
PlayerCommandSettings settings = new PlayerCommandSettings(
|
|
new PlayerCommandSettingsRepository() {
|
|
@Override public boolean loadEnabled() { return false; }
|
|
@Override public void saveEnabled(boolean enabled) throws IOException {
|
|
throw new IOException("disk full");
|
|
}
|
|
}
|
|
);
|
|
|
|
assertThrows(IOException.class, () -> settings.setEnabled(true));
|
|
|
|
assertFalse(settings.enabled());
|
|
}
|
|
}
|