|
24 | 24 | import com.google.android.material.shape.CornerTreatment; |
25 | 25 | import com.google.android.material.shape.CutCornerTreatment; |
26 | 26 | import com.google.android.material.shape.ShapeAppearanceModel; |
| 27 | +import androidx.core.content.ContextCompat; |
27 | 28 | import androidx.test.core.app.ApplicationProvider; |
28 | 29 | import org.junit.Before; |
29 | 30 | import org.junit.Test; |
30 | 31 | import org.junit.runner.RunWith; |
31 | 32 | import org.robolectric.RobolectricTestRunner; |
32 | 33 | import org.robolectric.annotation.internal.DoNotInstrument; |
| 34 | +import android.graphics.drawable.Drawable; |
| 35 | +import android.view.View.MeasureSpec; |
33 | 36 |
|
34 | 37 | /** Tests for {@link com.google.android.material.button.MaterialButton}. */ |
35 | 38 | @RunWith(RobolectricTestRunner.class) |
@@ -91,6 +94,27 @@ public void testGetShapeAppearanceModel() { |
91 | 94 | materialButton.getShapeAppearanceModel(), CUT_CORNER_FAMILY_CLASS); |
92 | 95 | } |
93 | 96 |
|
| 97 | + @Test |
| 98 | + public void setIcon_IconUpdated_whenCalledTwice() { |
| 99 | + MaterialButton materialButton = new MaterialButton(context); |
| 100 | + materialButton.setText("test"); |
| 101 | + int measureSpec = |
| 102 | + MeasureSpec.makeMeasureSpec(200, MeasureSpec.AT_MOST); |
| 103 | + |
| 104 | + Drawable drawable1 = ContextCompat.getDrawable(context, android.R.drawable.btn_plus); |
| 105 | + materialButton.setIcon(drawable1); |
| 106 | + materialButton.setIconGravity(MaterialButton.ICON_GRAVITY_START); |
| 107 | + materialButton.measure(measureSpec, measureSpec); |
| 108 | + |
| 109 | + assertThat(materialButton.getIcon()).isEqualTo(drawable1); |
| 110 | + |
| 111 | + Drawable drawable2 = ContextCompat.getDrawable(context, android.R.drawable.btn_minus); |
| 112 | + materialButton.setIcon(drawable2); |
| 113 | + materialButton.measure(measureSpec, measureSpec); |
| 114 | + |
| 115 | + assertThat(materialButton.getIcon()).isEqualTo(drawable2); |
| 116 | + } |
| 117 | + |
94 | 118 | private void assertThatCornerFamilyMatches( |
95 | 119 | ShapeAppearanceModel shapeAppearanceModel, |
96 | 120 | Class<? extends CornerTreatment> expectedCornerFamily) { |
|
0 commit comments