ButtonItem extends AbstractItem implements View.OnClickListener { protected Button createButton(ViewGroup parent) { if (mButton == null) { Context context = parent.getContext(); if (mTheme != 0) { context = new ContextThemeWrapper(context, mTheme); } mButton = createButton(context); mButton.setOnClickListener(this); } else { if (mButton.getParent() instanceof ViewGroup) { ((ViewGroup) mButton.getParent()).removeView(mButton); } } mButton.setEnabled(mEnabled); mButton.setText(mText); mButton.setId(getViewId()); return mButton; } ButtonItem();  ButtonItem(Context context, AttributeSet attrs); void setOnClickListener(OnClickListener listener); void setText(CharSequence text); CharSequence getText(); void setTheme(int theme); int getTheme(); void setEnabled(boolean enabled); @Override int getCount(); @Override boolean isEnabled(); @Override int getLayoutResource(); @Override final void onBindView(View view); @Override void onClick(View v);  }
@Test public void testCreateButton() { TestButtonItem item = new TestButtonItem(); final Button button = item.createButton(mParent); assertTrue("Default button should be enabled", button.isEnabled()); assertTrue("Default button text should be empty", TextUtils.isEmpty(button.getText())); }
@Test public void testButtonItemSetsItsId() { TestButtonItem item = new TestButtonItem(); final int id = 12345; item.setId(id); assertEquals("Button's id should be set", item.createButton(mParent).getId(), id); }
@Test public void testCreateButtonTwice() { TestButtonItem item = new TestButtonItem(); final Button button = item.createButton(mParent); FrameLayout frameLayout = new FrameLayout(mContext); frameLayout.addView(button); final Button button2 = item.createButton(mParent); assertSame("createButton should be reused", button, button2); assertNull("Should be removed from parent after createButton", button2.getParent()); }