FieldFormItem extends AbstractGrammarContainer { public int setFormItemVariable(final RecognitionResult result) throws SemanticError { final VoiceXmlInterpreterContext context = getContext(); final DataModel model = context.getDataModel(); final String shadowVariableName = getShadowVarContainerName(); final LastResult lastresult = toLastResult(model, result); model.updateVariable(shadowVariableName, lastresult); final Object interpretation = result.getSemanticInterpretation(model); if (interpretation == null) { final String utterance = result.getUtterance(); return super.setFormItemVariable(utterance); } else { final String slot = getSlot(); final String slotPath = "application.lastresult$.interpretation." + slot; if (model.existsVariable(slotPath)) { final Object value = model.readVariable(slotPath, Object.class); return super.setFormItemVariable(value); } else { return super.setFormItemVariable(interpretation); } } } FieldFormItem();  FieldFormItem(final VoiceXmlInterpreterContext context,
            final VoiceXmlNode voiceNode); @Override AbstractFormItem newInstance(final VoiceXmlInterpreterContext ctx,
            final VoiceXmlNode voiceNode); void setOptionConverter(final OptionConverter optionConverter); void accept(final FormItemVisitor visitor); int setFormItemVariable(final RecognitionResult result); int setFormItemVariable(final String utterance); @Override int setFormItemVariable(final Object value); String getSlot(); boolean isModal();  }
@Test public void setFormItemVariable() throws JVoiceXMLEvent { final DataModel model = Mockito.mock(DataModel.class); Mockito.when(context.getDataModel()).thenReturn(model); final String value = "test"; item.setFormItemVariable(value); Mockito.verify(model).updateVariable(item.getName(), value); final LastResult result = new LastResult(value); Mockito.verify(model).updateVariable(item.getName() + "$", result); }
@Test public void setFormItemVariableRecognitionResult() throws JVoiceXMLEvent { final RecognitionResult result = Mockito.mock(RecognitionResult.class); Mockito.when(result.getUtterance()).thenReturn("hans"); Mockito.when(result.isAccepted()).thenReturn(true); Mockito.when(result.getMode()).thenReturn(ModeType.VOICE); final DataModel model = Mockito.mock(DataModel.class); Mockito.when(model.readVariable(item.getName(), Object.class)) .thenReturn("hans"); Mockito.when(context.getDataModel()).thenReturn(model); item.setFormItemVariable(result); Assert.assertEquals(result.getUtterance(), item.getFormItemVariable()); }
@Test public void setFormItemVariableRecognitionResultSemanticInterpretation() throws JVoiceXMLEvent { final DataModel model = Mockito.mock(DataModel.class); final RecognitionResult result = Mockito.mock(RecognitionResult.class); Mockito.when(result.getUtterance()).thenReturn("yeah"); Mockito.when(result.getSemanticInterpretation(model)).thenReturn("yes"); Mockito.when(result.isAccepted()).thenReturn(true); Mockito.when(result.getMode()).thenReturn(ModeType.VOICE); Mockito.when(context.getDataModel()).thenReturn(model); item.setFormItemVariable(result); Mockito.verify(model).updateVariable(item.getName(), "yes"); }
@Test public void setFormItemVariableRecognitionResultSemanticSlot() throws JVoiceXMLEvent { final DataModel model = Mockito.mock(DataModel.class); final RecognitionResult result = Mockito.mock(RecognitionResult.class); Mockito.when(result.getUtterance()).thenReturn("a large pizza"); Mockito.when(result.getSemanticInterpretation(model)).thenReturn("large pizza"); Mockito.when(result.isAccepted()).thenReturn(true); Mockito.when(result.getMode()).thenReturn(ModeType.VOICE); Mockito.when(context.getDataModel()).thenReturn(model); Mockito.when(model.readVariable("application.lastresult$.interpretation.pizza.size", Object.class)) .thenReturn("large"); Mockito.when(model.existsVariable(endsWith("application.lastresult$.interpretation.pizza.size"))) .thenReturn(true); field.setSlot("pizza.size"); item.setFormItemVariable(result); Mockito.verify(model).updateVariable(item.getName(), "large"); }