ThemeUtil { public static String getString(final TypedArray typedArray, final int index) { final TypedValue value = typedArray.peekValue(index); if (value == null) { return null; } return typedArray.getString(index); } private  ThemeUtil(); static Drawable getDrawable(Context context, final TypedArray typedArray, final int index); static String getString(final TypedArray typedArray, final int index); @ColorInt static int getColor(Context context, int colorAttribute); static int getStyleId(Context context, int themeAttribute);  }
@Test public void testGetString() { final String valueStr = "value"; TypedArray typedArray = mock(TypedArray.class); TypedValue typedValue = spy(new TypedValue()); when(typedArray.peekValue(anyInt())).thenReturn(typedValue); when(typedArray.getString(anyInt())).thenReturn(valueStr); String ret = ThemeUtil.getString(typedArray, anyInt()); assertThat(ret, is(valueStr)); }
@Test public void testGetStringWhenTypeValueIsNull() { final String valueStr = "value"; TypedArray typedArray = mock(TypedArray.class); when(typedArray.getString(anyInt())).thenReturn(valueStr); String ret = ThemeUtil.getString(typedArray, anyInt()); assertNull(ret); }