### Question:
FacesUtils { public static Locale getLocale(FacesContext context) { Assert.notNull(context, "FacesContext must not be null"); if (context.getViewRoot() != null && context.getViewRoot().getLocale() != null) { return context.getViewRoot().getLocale(); } return context.getExternalContext().getRequestLocale(); }  static Locale getLocale(FacesContext context); @SuppressWarnings("unchecked") static T findParentOfType(UIComponent component, Class<T> parentType); static V doWithRequestScopeVariable(FacesContext context, String variableName, Object value,
			Callable<V> callable); static void doWithRequestScopeVariable(FacesContext context, String variableName, Object value,
			final Runnable runnable);  }### Answer:
@Test public void shouldNeedFacesContextForFindLocale() throws Exception { this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("FacesContext must not be null"); FacesUtils.getLocale(null); }
@Test public void shouldFindLocaleFromViewRoot() throws Exception { FacesContext facesContext = mock(FacesContext.class); UIViewRoot viewRoot = mock(UIViewRoot.class); ExternalContext externalContext = mock(ExternalContext.class); given(facesContext.getViewRoot()).willReturn(viewRoot); given(facesContext.getExternalContext()).willReturn(externalContext); given(viewRoot.getLocale()).willReturn(Locale.CANADA); given(externalContext.getRequestLocale()).willReturn(Locale.GERMAN); assertThat(FacesUtils.getLocale(facesContext), is(equalTo(Locale.CANADA))); }
@Test public void shouldFindLocaleFromRequestWhenNoViewRoot() throws Exception { FacesContext facesContext = mock(FacesContext.class); ExternalContext externalContext = mock(ExternalContext.class); given(facesContext.getExternalContext()).willReturn(externalContext); given(externalContext.getRequestLocale()).willReturn(Locale.GERMAN); assertThat(FacesUtils.getLocale(facesContext), is(equalTo(Locale.GERMAN))); }