@Test
  public void shouldSetValueAfterTextChange() {
    viewHolder.populate(viewModel, stockCard);

    viewHolder.etIssued.setText("30");
    assertEquals("30", viewModel.getIssued());
    assertEquals("70", viewModel.getStockExistence());
    assertEquals("70", viewHolder.txStockExistence.getText().toString());
  }
  @Test
  public void shouldEnableReceivedEditTextWhenModelWithReceivedType() {
    MovementReasonManager.MovementReason receivedReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.RECEIVE, "RECEIVE_1", "receive description");
    viewModel.setDraft(true);
    viewModel.setReason(receivedReason);
    viewHolder.populate(viewModel, stockCard);

    assertTrue(viewHolder.etReceived.isEnabled());
  }
  @Test
  public void shouldResetTxReasonValueWhenReuseViewModel() {
    viewHolder.populate(viewModel, stockCard);

    assertEquals(viewHolder.txReason.getText().toString(), "issue description");

    viewModel.setDraft(true);
    viewModel.setReason(null);
    viewHolder.populate(viewModel, stockCard);

    assertEquals(viewHolder.txReason.getText().toString(), "");
  }
  @Test
  public void shouldEnablePositiveAdjustmentEditTextWhenModelWithPositiveAdjustmentType() {
    MovementReasonManager.MovementReason positiveReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.POSITIVE_ADJUST,
            "POSITIVE_1",
            "positive adjustment description");
    viewModel.setDraft(true);
    viewModel.setReason(positiveReason);
    viewHolder.populate(viewModel, stockCard);

    assertTrue(viewHolder.etPositiveAdjustment.isEnabled());
  }
  @Test
  public void shouldNotClearInputWhenRotate() {
    viewHolder.populate(viewModel, stockCard);
    MovementReasonManager.MovementReason positiveReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.POSITIVE_ADJUST,
            "POSITIVE_1",
            "positive adjustment description");
    viewModel.setDraft(true);
    viewModel.setReason(positiveReason);
    viewHolder.etPositiveAdjustment.setText("10");

    viewHolder.populate(viewModel, stockCard);

    assertThat(viewHolder.etPositiveAdjustment.getText().toString(), is("10"));
  }
  @Test
  public void shouldEnableIssueEditTextWhenModelWithIssueType() {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);

    assertTrue(viewHolder.etIssued.isEnabled());
  }
  @Test
  public void shouldEnableIssueAndRequestedEditTextWhenChoseIssueMovementTypeWhenToggleIsOn()
      throws ParseException, LMISException {
    StockMovementViewHolder stockMovementViewHolder =
        new StockMovementViewHolder(itemView, mockedListener);

    viewModel.setDraft(true);
    stockMovementViewHolder.populate(viewModel, stockCard);
    stockMovementViewHolder.txMovementDate.setText("");

    StockMovementViewHolder.MovementSelectListener listener =
        stockMovementViewHolder.new MovementSelectListener(viewModel);

    MovementReasonManager.MovementReason receiveReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.ISSUE, "ISSUE_1", "issue description");

    listener.onComplete(receiveReason);

    assertFalse(stockMovementViewHolder.etReceived.isEnabled());
    assertFalse(stockMovementViewHolder.etPositiveAdjustment.isEnabled());
    assertFalse(stockMovementViewHolder.etNegativeAdjustment.isEnabled());
    assertTrue(stockMovementViewHolder.etIssued.isEnabled());
    assertTrue(stockMovementViewHolder.etRequested.isEnabled());
  }
  @Test
  public void shouldOnlyEnableCurrentSelectedEditTextWhenChoseMovementTypeWhenToggleIsOn()
      throws ParseException, LMISException {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);
    viewHolder.txMovementDate.setText("");

    StockMovementViewHolder.MovementSelectListener listener =
        viewHolder.new MovementSelectListener(viewModel);

    MovementReasonManager.MovementReason receiveReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.RECEIVE, "DON", "Donations");
    listener.onComplete(receiveReason);
    assertTrue(viewHolder.etReceived.isEnabled());
    assertFalse(viewHolder.etPositiveAdjustment.isEnabled());
    assertFalse(viewHolder.etNegativeAdjustment.isEnabled());
    assertFalse(viewHolder.etIssued.isEnabled());
    assertFalse(viewHolder.etRequested.isEnabled());

    MovementReasonManager.MovementReason positiveReason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.POSITIVE_ADJUST, "POSITIVE", "BOUGHT");
    listener.onComplete(positiveReason);

    assertFalse(viewHolder.etReceived.isEnabled());
    assertTrue(viewHolder.etPositiveAdjustment.isEnabled());
    assertFalse(viewHolder.etNegativeAdjustment.isEnabled());
    assertFalse(viewHolder.etIssued.isEnabled());
    assertFalse(viewHolder.etRequested.isEnabled());
  }
  @Test
  public void shouldEnableMovementTypeAndReasonIfModelIsDraft() {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);

    assertTrue(viewHolder.txMovementDate.isEnabled());
    assertTrue(viewHolder.txReason.isEnabled());
  }
  @Test
  public void shouldShowMovementDateDialogOnClick() {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);

    viewHolder.txMovementDate.performClick();

    DatePickerDialog datePickerDialog = (DatePickerDialog) ShadowDatePickerDialog.getLatestDialog();
    assertNotNull(datePickerDialog);
  }
  @Test
  public void shouldShowMovementTypeDialogOnClick() {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);

    viewHolder.txReason.performClick();

    AlertDialog typeDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(typeDialog);
  }
  @Test
  public void shouldValidateMovementDateOnSelectionAnd() throws ParseException, LMISException {
    viewHolder.populate(viewModel, stockCard);

    StockMovementViewHolder.MovementDateListener movementDateListener =
        viewHolder
        .new MovementDateListener(viewModel, DateUtil.parseString("11-11-2015", "MM-dd-YYYY"));
    movementDateListener.onDateSet(mock(DatePicker.class), 2015, 10, 15);
    assertEquals("15 Nov 2015", viewHolder.txMovementDate.getText().toString());
    assertEquals("15 Nov 2015", viewModel.getMovementDate());
    assertNull(ShadowToast.getLatestToast());
  }
  @Test
  public void shouldSetReasonAndDateOnComplete() {
    MovementReasonManager.MovementReason reason =
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.RECEIVE, "DON", "Donations");
    String today = DateUtil.formatDate(new Date());
    viewHolder.populate(viewModel, stockCard);
    viewHolder.txMovementDate.setText("");
    viewHolder.etIssued.setText("100");

    StockMovementViewHolder.MovementSelectListener listener =
        viewHolder.new MovementSelectListener(viewModel);
    listener.onComplete(reason);

    assertEquals(reason.getDescription(), viewHolder.txReason.getText().toString());
    assertEquals(reason.getDescription(), viewModel.getReason().getDescription());
    assertEquals(today, viewHolder.txMovementDate.getText().toString());
    assertEquals(today, viewModel.getMovementDate());
    assertTrue(viewHolder.etReceived.isEnabled());
    assertEquals(viewHolder.etIssued.getText().toString(), "");
    verify(mockedListener).movementChange();
  }
  @Test
  public void shouldPopulateTextDataWhenPopulatingData() {
    viewModel.setRequested("999");
    viewHolder.populate(viewModel, stockCard);

    assertEquals("12345", viewHolder.etDocumentNo.getText().toString());
    assertEquals("2015-11-11", viewHolder.txMovementDate.getText().toString());
    assertEquals("", viewHolder.etReceived.getText().toString());
    assertEquals("", viewHolder.etNegativeAdjustment.getText().toString());
    assertEquals("", viewHolder.etPositiveAdjustment.getText().toString());
    assertEquals("30", viewHolder.etIssued.getText().toString());
    assertEquals("70", viewHolder.txStockExistence.getText().toString());
    assertEquals("999", viewHolder.etRequested.getText().toString());
    assertEquals("issue description", viewHolder.txReason.getText().toString());
  }
  @Test
  public void shouldSetFontColorBlackIfIssueAdjustment() {
    viewModel.setReason(
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.ISSUE, "ISSUE_1", "issue description"));
    viewHolder.populate(viewModel, stockCard);

    int black = RuntimeEnvironment.application.getResources().getColor(R.color.color_black);

    assertEquals(black, viewHolder.txMovementDate.getCurrentTextColor());
    assertEquals(black, viewHolder.txReason.getCurrentTextColor());
    assertEquals(black, viewHolder.etDocumentNo.getCurrentTextColor());
    assertEquals(black, viewHolder.etReceived.getCurrentTextColor());
    assertEquals(black, viewHolder.etPositiveAdjustment.getCurrentTextColor());
    assertEquals(black, viewHolder.etNegativeAdjustment.getCurrentTextColor());
    assertEquals(black, viewHolder.txStockExistence.getCurrentTextColor());
  }
  @Test
  public void shouldSetFontColorRedIfNotIssueAdjustment() {
    viewModel.setReason(
        new MovementReasonManager.MovementReason(
            MovementReasonManager.MovementType.NEGATIVE_ADJUST,
            "negative_adjust",
            "negative_adjust description"));
    viewHolder.populate(viewModel, stockCard);

    int red = RuntimeEnvironment.application.getResources().getColor(R.color.color_red);

    assertEquals(red, viewHolder.txMovementDate.getCurrentTextColor());
    assertEquals(red, viewHolder.txReason.getCurrentTextColor());
    assertEquals(red, viewHolder.etDocumentNo.getCurrentTextColor());
    assertEquals(red, viewHolder.etReceived.getCurrentTextColor());
    assertEquals(red, viewHolder.etPositiveAdjustment.getCurrentTextColor());
    assertEquals(red, viewHolder.etNegativeAdjustment.getCurrentTextColor());
    assertEquals(red, viewHolder.txStockExistence.getCurrentTextColor());
  }