@@ -0,0 +1,3044 @@
+package com.abhi.fyberdemo.fragments;%0A%0Aimport android.support.v4.app.Fragment;%0Aimport android.view.View;%0A%0Aimport com.abhi.fyberdemo.BuildConfig;%0Aimport com.abhi.fyberdemo.MainActivity;%0Aimport com.abhi.fyberdemo.R;%0Aimport com.abhi.fyberdemo.models.OfferResponse;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mockito;%0Aimport org.robolectric.Robolectric;%0Aimport org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.annotation.Config;%0A%0A/**%0A * Created by abhi on 28/10/16.%0A */%0A%0A@RunWith(RobolectricTestRunner.class)%0A@Config(constants = BuildConfig.class, sdk = 23)%0Apublic class OffersFragmentTest %7B%0A    private MainActivity mMainActivity;%0A    private OffersFragment mOffersFragment;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        OfferResponse _offerResponse = Mockito.mock(OfferResponse.class);%0A        mMainActivity = Robolectric.setupActivity(MainActivity.class);%0A        mOffersFragment = OffersFragment.newInstance(mMainActivity, _offerResponse);%0A        startFragment(mOffersFragment);%0A    %7D%0A%0A    private void startFragment(Fragment fragment) %7B%0A        mMainActivity.getSupportFragmentManager()%0A                .beginTransaction()%0A                .add(R.id.frag_container, fragment)%0A                .commit();%0A    %7D%0A%0A    @Test%0A    public void newInstance() throws Exception %7B%0A        /*OfferResponse _offerResponse = Mockito.mock(OfferResponse.class);%0A        MainActivity _mainActivity = Mockito.mock(MainActivity.class);%0A        OffersFragment _offersFragment = OffersFragment.newInstance(_mainActivity,_offerResponse);*/%0A        Assert.assertNotNull(mOffersFragment);%0A        Assert.assertNotNull(mMainActivity);%0A    %7D%0A%0A    @Test%0A    public void setupUI() throws Exception %7B%0A%0A    %7D%0A%0A    @Test%0A    public void loadOffers() throws Exception %7B%0A        OfferResponse _offerResponse = mOffersFragment.getOfferResponse();%0A        Mockito.when(_offerResponse.containsOffers()).thenReturn(false);%0A        mOffersFragment.loadOffers(_offerResponse);%0A        Assert.assertEquals(%22No Offers Test is not displayed when there are no offers%22, mOffersFragment.mNoOffersTextView.getVisibility(), View.VISIBLE);%0A        Assert.assertEquals(%22RecyclerView is displayed when there are no offers%22, mOffersFragment.mOffersRecyclerView.getVisibility(), View.GONE);%0A%0A        Mockito.when(_offerResponse.containsOffers()).thenReturn(true);%0A        mOffersFragment.loadOffers(_offerResponse);%0A        Assert.assertEquals(%22No Offers Test is displayed when there are offers%22, mOffersFragment.mNoOffersTextView.getVisibility(), View.GONE);%0A        Assert.assertEquals(%22RecyclerView is not displayed when there are offers%22, mOffersFragment.mOffersRecyclerView.getVisibility(), View.VISIBLE);%0A    %7D%0A%0A    @Test%0A    public void getLayoutId() throws Exception %7B%0A        int layoutId = mOffersFragment.getLayoutId();%0A        Assert.assertTrue(%22Layout Id can not be 0 %22, layoutId != 0);%0A        Assert.assertTrue(%22Layout Id can not be negative %22, layoutId %3E 0);%0A    %7D%0A%7D

Add Unit test for OffersFragment using Roboelectric