BarcodeWidget extends QuestionWidget implements BinaryDataReceiver { @Override public void setBinaryData(Object answer) { String response = (String) answer; binding.barcodeAnswerText.setText(stripInvalidCharacters(response)); binding.barcodeButton.setText(getContext().getString(R.string.replace_barcode)); widgetValueChanged(); } BarcodeWidget(Context context, QuestionDetails questionDetails, WaitingForDataRegistry waitingForDataRegistry,
                         CameraUtils cameraUtils); @Override void clearAnswer(); @Override IAnswerData getAnswer(); @Override void setBinaryData(Object answer); @Override void setOnLongClickListener(OnLongClickListener l); @Override void cancelLongPress();  }
@Test public void setData_updatesWidgetAnswer_afterStrippingInvalidCharacters() { BarcodeWidget widget = createWidget(promptWithAnswer(null)); widget.setBinaryData("\ud800blah\b"); assertThat(widget.binding.barcodeAnswerText.getText().toString(), is("blah")); }
@Test public void setData_updatesButtonLabel() { BarcodeWidget widget = createWidget(promptWithAnswer(null)); widget.setBinaryData("\ud800blah\b"); assertThat(widget.binding.barcodeButton.getText(), is(widgetTestActivity.getString(R.string.replace_barcode))); }
@Test public void setData_callsValueChangeListener() { BarcodeWidget widget = createWidget(promptWithAnswer(null)); WidgetValueChangedListener valueChangedListener = mockValueChangedListener(widget); widget.setBinaryData("blah"); verify(valueChangedListener).widgetValueChanged(widget); }