title: How to read Android resource file values in unit testing
body: <p>I have an array resource. I want to make test to read and parse the values from xml resource. Here is the codes.</p>
  <pre><code>&lt;string-array name=&quot;names&quot;&gt;
      &lt;item&gt;Name1[?]200&lt;/item&gt;
      &lt;item&gt;Name2[?]125&lt;/item&gt;
      &lt;item&gt;Name3[?]142&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  <p>I want to capture above string resource and parse like below test case. But I couldn't achive.</p>
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class ReadAndParseNamesTest {
  
  @Mock
  private Context mockApplicationContext;
  @Mock
  private Resources mockContextResources;
  
  @Test
  public void readAndParseNamesTest() {
      
      MockitoAnnotations.initMocks(this);
  
      when(mockApplicationContext.getResources()).thenReturn(mockContextResources);
  
       String[] marray = {&quot;mock main class&quot;};
      when(mockContextResources.getStringArray(R.array.allah_names))
              .thenReturn(marray);
      for(int i = 0;i&lt;marray.length;i++){
          String[] deger = marray[i].split(&quot;[?]&quot;);
          System.out.println(&quot;Deger &quot;+i+&quot;: &quot;+deger[0] + &quot; &quot;+ deger[1]);
      }
    }
  }
  </code></pre>
  <p>I am getting <code>java.lang.ArrayIndexOutOfBoundsException: 1</code> exception because i can't get actual values. Any help will be appreciated. Thank you.</p>