### Question:
ChainProcess extends AbstractProcess { private void setValue(Object value, ParameterValue param){ final Class cs = param.getDescriptor().getValueClass(); value = convert(value, cs); param.setValue(value); } ChainProcess(final ChainProcessDescriptor desc, final ParameterValueGroup input); @Override ChainProcessDescriptor getDescriptor(); static T convert(final Object candidate, final Class<T> target); @Override void dismissProcess(); @Override String toString();  }### Answer:
@Test public void testSimpleChain() throws ProcessException{ final Chain chain = createSimpleChain(); final Set<MockProcessRegistry> registries = Collections.singleton(new MockProcessRegistry()); final ProcessDescriptor desc = new ChainProcessDescriptor(chain, MockProcessRegistry.IDENTIFICATION, registries); final ParameterValueGroup input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(15d); input.parameter("b").setValue(2d); final Process process = desc.createProcess(input); final ParameterValueGroup result = process.call(); assertEquals(12.5d, result.parameter("r").doubleValue(),0.000001); }
@Test public void testSimpleXmlRW() throws ProcessException, JAXBException, IOException{ final Chain before = createSimpleChain(); final File f = File.createTempFile("chain", ".xml"); before.write(f); final Chain chain = Chain.read(f); assertNotNull(chain.getInput("a")); assertNotNull(chain.getInput("a").getDefaultValue()); final Set<MockProcessRegistry> registries = Collections.singleton(new MockProcessRegistry()); final ProcessDescriptor desc = new ChainProcessDescriptor(chain, MockProcessRegistry.IDENTIFICATION, registries); final ParameterValueGroup input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(15d); input.parameter("b").setValue(2d); final Process process = desc.createProcess(input); final ParameterValueGroup result = process.call(); assertEquals(12.5d, result.parameter("r").doubleValue(),0.000001); }
@Test public void testBranchChain() throws ProcessException{ final Chain chain = createBranchChain(); final Set<MockProcessRegistry> registries = Collections.singleton(new MockProcessRegistry()); final ProcessDescriptor desc = new ChainProcessDescriptor(chain, MockProcessRegistry.IDENTIFICATION, registries); ParameterValueGroup input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(15d); Process process = desc.createProcess(input); ParameterValueGroup result = process.call(); assertEquals(250d, result.parameter("r").doubleValue(),0.000001); input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(-5d); process = desc.createProcess(input); result = process.call(); assertEquals(0.5d, result.parameter("r").doubleValue(),0.000001); }
@Test public void testBranchXmlRW() throws ProcessException, JAXBException, IOException{ final Chain before = createBranchChain(); final File f = File.createTempFile("chain", ".xml"); before.write(f); final Chain chain = Chain.read(f); final Set<MockProcessRegistry> registries = Collections.singleton(new MockProcessRegistry()); final ProcessDescriptor desc = new ChainProcessDescriptor(chain, MockProcessRegistry.IDENTIFICATION, registries); ParameterValueGroup input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(15d); Process process = desc.createProcess(input); ParameterValueGroup result = process.call(); assertEquals(250d, result.parameter("r").doubleValue(),0.000001); input = desc.getInputDescriptor().createValue(); input.parameter("a").setValue(-5d); process = desc.createProcess(input); result = process.call(); assertEquals(0.5d, result.parameter("r").doubleValue(),0.000001); }