@@ -0,0 +1,3269 @@
+package com.thuytrinh.transactionviewer.products;%0A%0Aimport android.content.res.Resources;%0A%0Aimport com.google.common.collect.Lists;%0Aimport com.thuytrinh.transactionviewer.BuildConfig;%0Aimport com.thuytrinh.transactionviewer.api.Transaction;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mockito;%0Aimport org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.RuntimeEnvironment;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport java.util.Collections;%0A%0Aimport rx.Observable;%0Aimport rx.observers.TestSubscriber;%0Aimport rx.subjects.PublishSubject;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0A@RunWith(RobolectricTestRunner.class)%0A@Config(constants = BuildConfig.class, sdk = 23)%0Apublic class ProductViewModelTest %7B%0A  private ProductViewModel viewModel;%0A  private Resources resources;%0A%0A  @Before public void before() %7B%0A    resources = RuntimeEnvironment.application.getResources();%0A    viewModel = new ProductViewModel(resources);%0A  %7D%0A%0A  /**%0A   * To be able to be sorted by %7B@link Observable#toSortedList()%7D.%0A   */%0A  @Test public void shouldBeComparable() %7B%0A    assertThat(viewModel).isInstanceOf(Comparable.class);%0A  %7D%0A%0A  @Test public void sortProductsByAZ() %7B%0A    final ImmutableProduct a = ImmutableProduct.builder()%0A        .sku(%22A%22)%0A        .transactions(Collections.emptyList())%0A        .build();%0A    final ProductViewModel lhs = new ProductViewModel(resources);%0A    lhs.setProduct(a);%0A%0A    final ImmutableProduct b = ImmutableProduct.builder()%0A        .sku(%22B%22)%0A        .transactions(Collections.emptyList())%0A        .build();%0A    final ProductViewModel rhs = new ProductViewModel(resources);%0A    rhs.setProduct(b);%0A    assertThat(lhs.compareTo(rhs)).isNegative();%0A  %7D%0A%0A  @Test public void shouldEmitSelectionEvent() %7B%0A    final PublishSubject%3CString%3E onSelected = PublishSubject.create();%0A    viewModel.setOnSelected(onSelected);%0A    viewModel.setProduct(%0A        ImmutableProduct.builder()%0A            .sku(%22A%22)%0A            .transactions(Collections.emptyList())%0A            .build()%0A    );%0A%0A    final TestSubscriber%3CString%3E subscriber = new TestSubscriber%3C%3E();%0A    onSelected.subscribe(subscriber);%0A    viewModel.select();%0A%0A    subscriber.assertValue(%22A%22);%0A  %7D%0A%0A  @Test public void shouldReflectSku() %7B%0A    viewModel.setProduct(%0A        ImmutableProduct.builder()%0A            .sku(%22A%22)%0A            .transactions(Lists.newArrayList())%0A            .build()%0A    );%0A    assertThat(viewModel.sku()).isEqualTo(%22A%22);%0A  %7D%0A%0A  @Test public void shouldReflectTransactionCountInSingular() %7B%0A    viewModel.setProduct(%0A        ImmutableProduct.builder()%0A            .sku(%22A%22)%0A            .transactions(Lists.newArrayList(%0A                Mockito.mock(Transaction.class)%0A            ))%0A            .build()%0A    );%0A    assertThat(viewModel.transactionCount()).isEqualTo(%221 transaction%22);%0A  %7D%0A%0A  @Test public void shouldReflectTransactionCountInPlural() %7B%0A    viewModel.setProduct(%0A        ImmutableProduct.builder()%0A            .sku(%22A%22)%0A            .transactions(Lists.newArrayList(%0A                Mockito.mock(Transaction.class),%0A                Mockito.mock(Transaction.class)%0A            ))%0A            .build()%0A    );%0A    assertThat(viewModel.transactionCount()).isEqualTo(%222 transactions%22);%0A  %7D%0A%7D%0A

Write tests for ProductViewModel