|
| 1 | +package com.google.unity.ads.nativead; |
| 2 | + |
| 3 | +import static com.google.common.truth.Truth.assertThat; |
| 4 | + |
| 5 | +import android.graphics.Color; |
| 6 | +import android.graphics.drawable.ColorDrawable; |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | +import org.robolectric.RobolectricTestRunner; |
| 11 | + |
| 12 | +/** Tests for {@link UnityNativeTemplateStyle} */ |
| 13 | +@RunWith(RobolectricTestRunner.class) |
| 14 | +public final class UnityNativeTemplateStyleTest { |
| 15 | + |
| 16 | + private UnityNativeTemplateStyle unityNativeTemplateStyle; |
| 17 | + |
| 18 | + @Before |
| 19 | + public void setUp() { |
| 20 | + unityNativeTemplateStyle = |
| 21 | + new UnityNativeTemplateStyle( |
| 22 | + /* templateType= */ UnityNativeTemplateType.SMALL, |
| 23 | + /* mainBackgroundColor= */ new ColorDrawable(Color.RED), |
| 24 | + /* callToActionStyle= */ new UnityNativeTemplateTextStyle( |
| 25 | + /* textColor= */ new ColorDrawable(Color.GREEN), |
| 26 | + /* backgroundColor= */ new ColorDrawable(Color.BLUE), |
| 27 | + /* fontStyle= */ UnityNativeTemplateFontStyle.ITALIC, |
| 28 | + /* size= */ 1.0), |
| 29 | + /* primaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 30 | + /* textColor= */ new ColorDrawable(Color.RED), |
| 31 | + /* backgroundColor= */ new ColorDrawable(Color.BLUE), |
| 32 | + /* fontStyle= */ UnityNativeTemplateFontStyle.ITALIC, |
| 33 | + /* size= */ 5.0), |
| 34 | + /* secondaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 35 | + /* textColor= */ new ColorDrawable(Color.RED), |
| 36 | + /* backgroundColor= */ new ColorDrawable(Color.BLUE), |
| 37 | + /* fontStyle= */ UnityNativeTemplateFontStyle.ITALIC, |
| 38 | + /* size= */ 20.0), |
| 39 | + /* tertiaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 40 | + /* textColor= */ new ColorDrawable(Color.RED), |
| 41 | + /* backgroundColor= */ new ColorDrawable(Color.BLUE), |
| 42 | + /* fontStyle= */ UnityNativeTemplateFontStyle.ITALIC, |
| 43 | + /* size= */ 10.0)); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void unityNativeTemplateStyle_canBeInstantiated() throws Exception { |
| 48 | + assertThat(unityNativeTemplateStyle.getTemplateType()).isEqualTo(UnityNativeTemplateType.SMALL); |
| 49 | + assertThat(unityNativeTemplateStyle.getMainBackgroundColor().getColor()).isEqualTo(Color.RED); |
| 50 | + assertThat(unityNativeTemplateStyle.hashCode()).isNotEqualTo(0); |
| 51 | + |
| 52 | + UnityNativeTemplateTextStyle callToActionStyle = |
| 53 | + unityNativeTemplateStyle.getCallToActionStyle(); |
| 54 | + assertThat(callToActionStyle.getTextColor().getColor()).isEqualTo(Color.GREEN); |
| 55 | + assertThat(callToActionStyle.getBackgroundColor().getColor()).isEqualTo(Color.BLUE); |
| 56 | + assertThat(callToActionStyle.getFontStyle()).isEqualTo(UnityNativeTemplateFontStyle.ITALIC); |
| 57 | + assertThat(callToActionStyle.getSize()).isEqualTo(1.0f); |
| 58 | + |
| 59 | + UnityNativeTemplateTextStyle primaryTextStyle = unityNativeTemplateStyle.getPrimaryTextStyle(); |
| 60 | + assertThat(primaryTextStyle.getTextColor().getColor()).isEqualTo(Color.RED); |
| 61 | + assertThat(primaryTextStyle.getBackgroundColor().getColor()).isEqualTo(Color.BLUE); |
| 62 | + assertThat(primaryTextStyle.getFontStyle()).isEqualTo(UnityNativeTemplateFontStyle.ITALIC); |
| 63 | + assertThat(primaryTextStyle.getSize()).isEqualTo(5.0f); |
| 64 | + |
| 65 | + UnityNativeTemplateTextStyle secondaryTextStyle = |
| 66 | + unityNativeTemplateStyle.getSecondaryTextStyle(); |
| 67 | + assertThat(secondaryTextStyle.getTextColor().getColor()).isEqualTo(Color.RED); |
| 68 | + assertThat(secondaryTextStyle.getBackgroundColor().getColor()).isEqualTo(Color.BLUE); |
| 69 | + assertThat(secondaryTextStyle.getFontStyle()).isEqualTo(UnityNativeTemplateFontStyle.ITALIC); |
| 70 | + assertThat(secondaryTextStyle.getSize()).isEqualTo(20.0f); |
| 71 | + |
| 72 | + UnityNativeTemplateTextStyle tertiaryTextStyle = |
| 73 | + unityNativeTemplateStyle.getTertiaryTextStyle(); |
| 74 | + assertThat(tertiaryTextStyle.getTextColor().getColor()).isEqualTo(Color.RED); |
| 75 | + assertThat(tertiaryTextStyle.getBackgroundColor().getColor()).isEqualTo(Color.BLUE); |
| 76 | + assertThat(tertiaryTextStyle.getFontStyle()).isEqualTo(UnityNativeTemplateFontStyle.ITALIC); |
| 77 | + assertThat(tertiaryTextStyle.getSize()).isEqualTo(10.0f); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void unityNativeTemplateStyle_canBeCompared() throws Exception { |
| 82 | + UnityNativeTemplateStyle anotherUnityNativeTemplateStyle = |
| 83 | + new UnityNativeTemplateStyle( |
| 84 | + /* templateType= */ UnityNativeTemplateType.MEDIUM, |
| 85 | + /* mainBackgroundColor= */ new ColorDrawable(Color.GREEN), |
| 86 | + /* callToActionStyle= */ new UnityNativeTemplateTextStyle( |
| 87 | + /* textColor= */ new ColorDrawable(Color.GREEN), |
| 88 | + /* backgroundColor= */ new ColorDrawable(Color.YELLOW), |
| 89 | + /* fontStyle= */ UnityNativeTemplateFontStyle.BOLD, |
| 90 | + /* size= */ 30.0), |
| 91 | + /* primaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 92 | + /* textColor= */ new ColorDrawable(Color.GREEN), |
| 93 | + /* backgroundColor= */ new ColorDrawable(Color.YELLOW), |
| 94 | + /* fontStyle= */ UnityNativeTemplateFontStyle.BOLD, |
| 95 | + /* size= */ 30.0), |
| 96 | + /* secondaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 97 | + /* textColor= */ new ColorDrawable(Color.GREEN), |
| 98 | + /* backgroundColor= */ new ColorDrawable(Color.YELLOW), |
| 99 | + /* fontStyle= */ UnityNativeTemplateFontStyle.BOLD, |
| 100 | + /* size= */ 30.0), |
| 101 | + /* tertiaryTextStyle= */ new UnityNativeTemplateTextStyle( |
| 102 | + /* textColor= */ new ColorDrawable(Color.GREEN), |
| 103 | + /* backgroundColor= */ new ColorDrawable(Color.YELLOW), |
| 104 | + /* fontStyle= */ UnityNativeTemplateFontStyle.BOLD, |
| 105 | + /* size= */ 30.0)); |
| 106 | + assertThat(unityNativeTemplateStyle).isNotEqualTo(anotherUnityNativeTemplateStyle); |
| 107 | + assertThat(unityNativeTemplateStyle.hashCode()) |
| 108 | + .isNotEqualTo(anotherUnityNativeTemplateStyle.hashCode()); |
| 109 | + } |
| 110 | +} |
0 commit comments