Test fixes

This commit is contained in:
dragonmacher
2022-11-21 09:54:08 -05:00
parent 75ddd08bbd
commit 0eafe44445
4 changed files with 42 additions and 22 deletions

View File

@@ -175,9 +175,8 @@ public abstract class AbstractOptions implements Options {
}
private void warnShouldUseTheme(String optionType) {
Throwable throwable =
ReflectionUtilities.createThrowableWithStackOlderThan(AbstractOptions.class,
SubOptions.class);
Throwable throwable = ReflectionUtilities
.createThrowableWithStackOlderThan(AbstractOptions.class, SubOptions.class);
String call = throwable.getStackTrace()[0].toString();
Msg.warn(this, "Registering a direct " + optionType + " in the options is deprecated." +
" Use registerTheme" + optionType + "Binding() instead!\n Called from " + call + "\n");
@@ -343,8 +342,15 @@ public abstract class AbstractOptions implements Options {
Object oldValue = option.getCurrentValue();
option.setCurrentValue(newValue);
if (!notifyOptionChanged(optionName, oldValue, newValue)) {
option.setCurrentValue(oldValue);
boolean success = false;
try {
// this can throw an OptionsVetoException
success = notifyOptionChanged(optionName, oldValue, newValue);
}
finally {
if (!success) {
option.setCurrentValue(oldValue);
}
}
}

View File

@@ -117,16 +117,25 @@ public class EditorState implements PropertyChangeListener {
return;
}
options.putObject(name, currentValue);
Object newValue = options.getObject(name, null);
boolean success = Objects.equals(currentValue, newValue);
if (success) {
originalValue = newValue;
currentValue = newValue;
//
// The call to put() may throw an exception or may choose not to take the new value. Handle
// both cases using a finally block along with checking the value after making the put()
// call.
//
try {
options.putObject(name, currentValue);
}
else {
editor.setValue(originalValue);
currentValue = originalValue;
finally {
Object newValue = options.getObject(name, null);
boolean success = Objects.equals(currentValue, newValue);
if (success) {
originalValue = newValue;
currentValue = newValue;
}
else {
editor.setValue(originalValue);
currentValue = originalValue;
}
}
}