Skip to content

Commit

Permalink
Don't persist test inputs
Browse files Browse the repository at this point in the history
If inputs are pesisted then they may be populated even without the
MockInputHarvester, which is confusing.
  • Loading branch information
hinerm committed Sep 18, 2020
1 parent a63cd8f commit 3d64e2a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/test/java/org/scijava/command/InputsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.junit.Test;
import org.scijava.Context;
import org.scijava.InstantiableException;
import org.scijava.log.LogLevel;
import org.scijava.log.LogService;
import org.scijava.module.Module;
import org.scijava.module.ModuleItem;
import org.scijava.module.MutableModuleItem;
Expand Down Expand Up @@ -81,7 +79,7 @@ public void testSingleInput() {
}});
Inputs inputs = new Inputs(context);
inputs.getInfo().setName("testSingleInput");//TEMP
inputs.addInput("sigma", Float.class);
addTempInput(inputs, "sigma", Float.class);
float sigma = (Float) inputs.harvest().get("sigma");
assertEquals(3.9f, sigma, 0);
}
Expand All @@ -95,8 +93,8 @@ public void testTwoInputs() {
}});
Inputs inputs = new Inputs(context);
inputs.getInfo().setName("testTwoInputs");//TEMP
inputs.addInput("name", String.class);
inputs.addInput("age", Integer.class);
addTempInput(inputs, "name", String.class);
addTempInput(inputs, "age", Integer.class);
Map<String, Object> values = inputs.harvest();
String name = (String) values.get("name");
int age = (Integer) values.get("age");
Expand All @@ -113,11 +111,13 @@ public void testWithConfiguration() {
}});
Inputs inputs = new Inputs(context);
inputs.getInfo().setName("testWithConfiguration");//TEMP
MutableModuleItem<String> wordInput = inputs.addInput("word", String.class);
MutableModuleItem<String> wordInput = addTempInput(inputs, "word",
String.class);
wordInput.setLabel("Favorite word");
wordInput.setChoices(Arrays.asList("quick", "brown", "fox"));
wordInput.setDefaultValue("fox");
MutableModuleItem<Double> opacityInput = inputs.addInput("opacity", Double.class);
MutableModuleItem<Double> opacityInput = addTempInput(inputs, "opacity",
Double.class);
opacityInput.setMinimumValue(0.0);
opacityInput.setMaximumValue(1.0);
opacityInput.setDefaultValue(0.5);
Expand Down Expand Up @@ -145,6 +145,18 @@ public PreprocessorPlugin createInstance() throws InstantiableException {
context.service(PluginService.class).addPlugin(info);
}

/**
* Add a non-persisted input to ensure we are testing with the mock input
* harvester.
*/
private static <T> MutableModuleItem<T> addTempInput(Inputs inputs,
String inputName, Class<T> inputType)
{
MutableModuleItem<T> input = inputs.addInput(inputName, inputType);
input.setPersisted(false);
return input;
}

public static class MockInputHarvester extends AbstractPreprocessorPlugin {
private Map<String, Object> expected;
public void setExpected(final Map<String, Object> expected) {
Expand Down

0 comments on commit 3d64e2a

Please sign in to comment.