title: Mocking Locale.forLanguageTag
body: <p>I'm trying to unit test a method that does</p>
  
  <pre><code>public static Context fromLanguageTag(final String languageTag) {
      final Context context = new Context();
      final Locale locale = Locale.forLanguageTag(languageTag);
      context.language = locale.getLanguage().length()==3 ? locale.getLanguage() : locale.getISO3Language();
      return context;
  }
  </code></pre>
  
  <p>To test that I need to mock <code>java.util.Locale</code>. I'm using PowerMock and Mockito:</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({ Locale.class })
  public class ContextTest {  
      public void testFromLanguageTag() throws Exception {
         mockStatic(Locale.class);
         final Locale mockLocale = mock(Locale.class);
         when(mockLocale.getLanguage()).thenReturn(LANGUAGE_3_OUTPUT);
         when(mockLocale.getISO3Language()).thenReturn(LANGUAGE_ISO);
         when(Locale.forLanguageTag(Mockito.eq(LANGUAGE_TAG_LONG_INPUT))).thenReturn(mockLocale);
         final Context c = Context.fromLanguageTag(LANGUAGE_TAG_LONG_INPUT);
         assertThat(c.getLanguage()).isEqualTo(LANGUAGE_3_OUTPUT);
     }
  }
  </code></pre>
  
  <p>But it seems the mocked method calls from <code>mockLocale</code> are never called; instead I get a <code>java.util.MissingResourceException</code> from <code>java.util.Locale.getISO3Language</code> (which I want to mock). How can fix that?</p>