Skip to content

Commit

Permalink
Made sure that icon-only tabs throw an exception if they don't have i…
Browse files Browse the repository at this point in the history
…cons.
  • Loading branch information
roughike committed Mar 27, 2017
1 parent 8fe38ac commit 0c8c8f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,33 @@ public void setUp() {
}

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

@Test(expected = IllegalStateException.class)
public void setType_ToTitleless_WhenIconDoesNotExist_ThrowsException() {
tab.setType(BottomBarTab.Type.TITLELESS);
assertEquals(R.layout.bb_bottom_bar_item_titleless, tab.getLayoutResource());
}

@Test
public void correctLayoutReturned_ForTitlelessTab() {
public void correctLayoutForTitlelessTab() {
tab.setIconResId(com.roughike.bottombar.test.R.drawable.empty_icon);
tab.setType(BottomBarTab.Type.TITLELESS);

assertEquals(R.layout.bb_bottom_bar_item_titleless, tab.getLayoutResource());
}

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

@Test
public void correctLayoutReturned_ForTabletTab() {
public void correctLayoutForTabletTab() {
tab.setType(BottomBarTab.Type.TABLET);
assertEquals(R.layout.bb_bottom_bar_item_fixed_tablet, tab.getLayoutResource());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ Type getType() {
}

void setType(Type type) {
if (type == Type.TITLELESS && getIconResId() == 0) {
throw new IllegalStateException("This tab is supposed to be " +
"icon only, yet it has no icon specified. Index in " +
"container: " + getIndexInTabContainer());
}

this.type = type;
}

Expand Down

0 comments on commit 0c8c8f1

Please sign in to comment.