<commit_before>package org.openlmis.core.view.activity;

import android.content.Intent;

import com.google.inject.AbstractModule;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openlmis.core.LMISTestApp;
import org.openlmis.core.LMISTestRunner;
import org.openlmis.core.R;
import org.openlmis.core.model.Product;
import org.openlmis.core.model.builder.ProductBuilder;
import org.openlmis.core.presenter.UnpackKitPresenter;
import org.openlmis.core.utils.Constants;
import org.openlmis.core.view.viewmodel.InventoryViewModel;
import org.openlmis.core.view.viewmodel.StockCardViewModelBuilder;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;

import roboguice.RoboGuice;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@RunWith(LMISTestRunner.class)
public class UnpackKitActivityTest {

    private UnpackKitPresenter mockedPresenter;
    private UnpackKitActivity stockMovementActivity;
    private Product product;
    private InventoryViewModel viewModel;

    @Before
    public void setUp() throws Exception {

        product = new ProductBuilder().setIsKit(false).setCode("productCode1").setPrimaryName("name1").build();
        viewModel = new StockCardViewModelBuilder(product).setChecked(true).setKitExpectQuantity(300).setQuantity("200").build();

        mockedPresenter = mock(UnpackKitPresenter.class);

        RoboGuice.overrideApplicationInjector(RuntimeEnvironment.application, new AbstractModule() {
            @Override
            protected void configure() {
                bind(UnpackKitPresenter.class).toInstance(mockedPresenter);
            }
        });

        Intent intent = new Intent()
                .putExtra(Constants.PARAM_KIT_CODE, "SD0001")
                .putExtra(Constants.PARAM_KIT_NUM, 1);
        stockMovementActivity = Robolectric.buildActivity(UnpackKitActivity.class).withIntent(intent).create().visible().get();
    }

    @Test
    public void shouldLoadKitProductsWithKitCode() throws Exception {
        verify(mockedPresenter).loadKitProducts("SD0001", 1);
    }

    @Test
    public void shouldShowDialogWhenQuantityIsValid() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, true);
        stockMovementActivity.refreshList(Arrays.asList(viewModel));

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        assertNotNull(stockMovementActivity.getFragmentManager().findFragmentByTag("signature_dialog_for_unpack_kit"));
    }

    @Test
    public void shouldNotShowDialogWhenQuantityIsNotValid() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, true);
        viewModel.setQuantity("");
        stockMovementActivity.refreshList(Arrays.asList(viewModel));

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        assertNull(stockMovementActivity.getFragmentManager().findFragmentByTag("signature_dialog_for_unpack_kit"));
    }

    @Test
    public void shouldSaveUnpackMovementsWhenQuantityIsValidWhenToggleOff() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, false);
        stockMovementActivity.refreshList(Arrays.asList(viewModel));
        stockMovementActivity.etDocumentNumber.setText("DocumentNumber");

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();
        verify(mockedPresenter).saveUnpackProducts(1, "DocumentNumber", "");
    }

    @Test
    public void shouldNotSaveUnpackMovementsWhenQuantityIsNotValidWhenToggleOff() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, false);
        viewModel.setQuantity("");
        stockMovementActivity.refreshList(Arrays.asList(viewModel));
        stockMovementActivity.etDocumentNumber.setText("DocumentNumber");

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        verify(mockedPresenter, never()).saveUnpackProducts(1, "DocumentNumber", "");
    }
}<commit_msg>SZW&HK -#674 -Limit the length of document number in unpack kit page fix unit test<commit_after>package org.openlmis.core.view.activity;

import android.content.Intent;

import com.google.inject.AbstractModule;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openlmis.core.LMISTestApp;
import org.openlmis.core.LMISTestRunner;
import org.openlmis.core.R;
import org.openlmis.core.model.Product;
import org.openlmis.core.model.builder.ProductBuilder;
import org.openlmis.core.presenter.UnpackKitPresenter;
import org.openlmis.core.utils.Constants;
import org.openlmis.core.view.viewmodel.InventoryViewModel;
import org.openlmis.core.view.viewmodel.StockCardViewModelBuilder;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;

import roboguice.RoboGuice;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@RunWith(LMISTestRunner.class)
public class UnpackKitActivityTest {

    private UnpackKitPresenter mockedPresenter;
    private UnpackKitActivity stockMovementActivity;
    private Product product;
    private InventoryViewModel viewModel;

    @Before
    public void setUp() throws Exception {

        product = new ProductBuilder().setIsKit(false).setCode("productCode1").setPrimaryName("name1").build();
        viewModel = new StockCardViewModelBuilder(product).setChecked(true).setKitExpectQuantity(300).setQuantity("200").build();

        mockedPresenter = mock(UnpackKitPresenter.class);

        RoboGuice.overrideApplicationInjector(RuntimeEnvironment.application, new AbstractModule() {
            @Override
            protected void configure() {
                bind(UnpackKitPresenter.class).toInstance(mockedPresenter);
            }
        });

        Intent intent = new Intent()
                .putExtra(Constants.PARAM_KIT_CODE, "SD0001")
                .putExtra(Constants.PARAM_KIT_NUM, 1);
        stockMovementActivity = Robolectric.buildActivity(UnpackKitActivity.class).withIntent(intent).create().visible().get();
    }

    @Test
    public void shouldLoadKitProductsWithKitCode() throws Exception {
        verify(mockedPresenter).loadKitProducts("SD0001", 1);
    }

    @Test
    public void shouldShowDialogWhenQuantityIsValid() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, true);
        stockMovementActivity.refreshList(Arrays.asList(viewModel));

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        assertNotNull(stockMovementActivity.getFragmentManager().findFragmentByTag("signature_dialog_for_unpack_kit"));
    }

    @Test
    public void shouldNotShowDialogWhenQuantityIsNotValid() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, true);
        viewModel.setQuantity("");
        stockMovementActivity.refreshList(Arrays.asList(viewModel));

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        assertNull(stockMovementActivity.getFragmentManager().findFragmentByTag("signature_dialog_for_unpack_kit"));
    }

    @Test
    public void shouldSaveUnpackMovementsWhenQuantityIsValidWhenToggleOff() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, false);
        stockMovementActivity.refreshList(Arrays.asList(viewModel));
        stockMovementActivity.etDocumentNumber.setText("DocumentNumber");

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();
        verify(mockedPresenter).saveUnpackProducts(1, "DocumentN", "");
    }

    @Test
    public void shouldNotSaveUnpackMovementsWhenQuantityIsNotValidWhenToggleOff() throws Exception {
        LMISTestApp.getInstance().setFeatureToggle(R.bool.feature_signature_for_unpack_kit, false);
        viewModel.setQuantity("");
        stockMovementActivity.refreshList(Arrays.asList(viewModel));
        stockMovementActivity.etDocumentNumber.setText("DocumentNumber");

        stockMovementActivity.mAdapter.onCreateViewHolder(stockMovementActivity.productListRecycleView, 1).itemView.findViewById(R.id.btn_complete).performClick();

        verify(mockedPresenter, never()).saveUnpackProducts(1, "DocumentNumber", "");
    }
}
{'fraction_non_alphanumeric': 0.09732256693582661, 'fraction_numerical': 0.005418614534636634, 'mean_word_length': 4.9993626513703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5530066', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2617, 'n_words': 342}