### Question:
CardMultilineWidget extends LinearLayout { public void setShouldShowPostalCode(boolean shouldShowPostalCode) { mShouldShowPostalCode = shouldShowPostalCode; adjustViewForPostalCodeAttribute(); } CardMultilineWidget(Context context);  CardMultilineWidget(Context context, AttributeSet attrs);  CardMultilineWidget(Context context, AttributeSet attrs, int defStyleAttr); @VisibleForTesting  CardMultilineWidget(Context context, boolean shouldShowPostalCode); void clear(); void setCardInputListener(@Nullable CardInputListener cardInputListener); @Nullable Card getCard(); boolean validateAllFields(); @Override void onWindowFocusChanged(boolean hasWindowFocus); void setShouldShowPostalCode(boolean shouldShowPostalCode); @Override boolean isEnabled(); @Override void setEnabled(boolean enabled);  }### Answer:
@Test public void initView_whenZipRequiredThenSetToHidden_secondRowLosesPostalCodeAndAdjustsMargin() { assertEquals(View.VISIBLE, mFullGroup.postalCodeInputLayout.getVisibility()); mCardMultilineWidget.setShouldShowPostalCode(false); assertEquals(View.GONE, mFullGroup.postalCodeInputLayout.getVisibility()); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mFullGroup.cvcInputLayout.getLayoutParams(); assertEquals(0, params.rightMargin); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { assertEquals(0, params.getMarginEnd()); } }
@Test public void initView_whenZipHiddenThenSetToRequired_secondRowAddsPostalCodeAndAdjustsMargin() { assertEquals(View.GONE, mNoZipGroup.postalCodeInputLayout.getVisibility()); mNoZipCardMultilineWidget.setShouldShowPostalCode(true); assertEquals(View.VISIBLE, mNoZipGroup.postalCodeInputLayout.getVisibility()); int expectedMargin = mNoZipCardMultilineWidget.getResources() .getDimensionPixelSize(R.dimen.add_card_expiry_middle_margin); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mNoZipGroup.cvcInputLayout.getLayoutParams(); assertEquals(expectedMargin, params.rightMargin); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { assertEquals(expectedMargin, params.getMarginEnd()); } }