BarcodeWidget extends QuestionWidget implements BinaryDataReceiver { @Override public void clearAnswer() { binding.barcodeAnswerText.setText(null); binding.barcodeButton.setText(getContext().getString(R.string.get_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 clearAnswer_clearsWidgetAnswer() { BarcodeWidget widget = createWidget(promptWithAnswer(new StringData("blah"))); widget.clearAnswer(); assertThat(widget.binding.barcodeAnswerText.getText().toString(), is("")); assertThat(widget.binding.barcodeButton.getText().toString(), is(widgetTestActivity.getString(R.string.get_barcode))); }
@Test public void clearAnswer_callsValueChangeListener() { BarcodeWidget widget = createWidget(promptWithAnswer(new StringData("blah"))); WidgetValueChangedListener valueChangedListener = mockValueChangedListener(widget); widget.clearAnswer(); verify(valueChangedListener).widgetValueChanged(widget); }