Skip to content

Commit

Permalink
Increased test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
roughike committed Aug 22, 2016
1 parent 4114131 commit 1d42253
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* Created by iiro on 8.8.2016.
Expand Down Expand Up @@ -55,26 +58,20 @@ public void run() {
@Test
@UiThreadTest
public void whenBadgeCountIsZero_BadgeIsRemoved() {
assertNotNull(nearby.badge);

nearby.setBadgeCount(0);
assertNull(nearby.badge);
}

@Test
@UiThreadTest
public void whenBadgeCountIsNegative_BadgeIsRemoved() {
assertNotNull(nearby.badge);

nearby.setBadgeCount(-1);
assertNull(nearby.badge);
}

@Test
@UiThreadTest
public void whenBadgeStateRestored_CountPersists() {
assertNotNull(nearby.badge);

nearby.setBadgeCount(1);
assertEquals(1, nearby.badge.getCount());

Expand All @@ -86,4 +83,16 @@ public void whenBadgeStateRestored_CountPersists() {

assertEquals(2, nearby.badge.getCount());
}

@Test
@UiThreadTest
public void badgeRemovedProperly() {
assertNotEquals(bottomBar.findViewById(R.id.bb_bottom_bar_item_container), nearby.getOuterView());
assertEquals(2, nearby.getOuterView().getChildCount());
assertTrue(nearby.getOuterView().getChildAt(1) instanceof BottomBarBadge);

nearby.removeBadge();
assertNull(nearby.badge);
assertEquals(bottomBar.findViewById(R.id.bb_bottom_bar_item_container), nearby.getOuterView());
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
package com.roughike.bottombar;

import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.widget.FrameLayout;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
* Created by iiro on 22.8.2016.
*/
@RunWith(AndroidJUnit4.class)
public class BottomBarTabTest {
private FrameLayout tabContainer;
private BottomBarTab tab;

@Before
public void setUp() {
tabContainer = new FrameLayout(InstrumentationRegistry.getContext());
tab = new BottomBarTab(InstrumentationRegistry.getContext());

tabContainer.addView(tab);
}

@Test
public void correctLayoutReturned_ForFixedTab() {
tab.setType(BottomBarTab.Type.FIXED);
assertEquals(R.layout.bb_bottom_bar_item_fixed, tab.getLayoutResource());
}

@Test
public void test() {
public void correctLayoutReturned_ForShiftingTab() {
tab.setType(BottomBarTab.Type.SHIFTING);
assertEquals(R.layout.bb_bottom_bar_item_shifting, tab.getLayoutResource());
}

@Test
public void correctLayoutReturned_ForTabletTab() {
tab.setType(BottomBarTab.Type.TABLET);
assertEquals(R.layout.bb_bottom_bar_item_fixed_tablet, tab.getLayoutResource());
}

@Test
public void testSavedStateWithBadge_StaysIntact() {
tab.setBadgeCount(5);
tab.setIndexInContainer(69);
assertEquals(69, tab.getIndexInTabContainer());

Bundle savedState = (Bundle) tab.onSaveInstanceState();
assertEquals(5, savedState.getInt(BottomBarBadge.STATE_COUNT + 69));

tab.setBadgeCount(9);
assertEquals(9, tab.badge.getCount());

tab.onRestoreInstanceState(savedState);
assertEquals(5, tab.badge.getCount());
}
}

0 comments on commit 1d42253

Please sign in to comment.