diff --git a/bottom-bar/src/androidTest/java/com/roughike/bottombar/BottomBarTabTest.java b/bottom-bar/src/androidTest/java/com/roughike/bottombar/BottomBarTabTest.java index e7a6f9df..6b9c6312 100644 --- a/bottom-bar/src/androidTest/java/com/roughike/bottombar/BottomBarTabTest.java +++ b/bottom-bar/src/androidTest/java/com/roughike/bottombar/BottomBarTabTest.java @@ -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()); } diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java index d606de95..c841073a 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java @@ -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; }