LocaleExtractor { public Locale extractFromAccept(String accept) throws LocaleNotFoundException { if(null != accept) { Pattern pattern = Pattern.compile(".*(\\w\\w)-(\\w\\w).*"); Matcher matcher = pattern.matcher(accept); if (matcher.matches()) { return new Locale(matcher.group(1), matcher.group(2)); } } throw new LocaleNotFoundException(); }  Locale extractFromAccept(String accept);  }
@Test(expected = LocaleNotFoundException.class) public void testExtractFromAcceptNok3() throws LocaleNotFoundException { instance.extractFromAccept(null); }
@Test public void testExtractFromAccept() throws LocaleNotFoundException { Locale result = instance.extractFromAccept("fr-FR;q=1"); assertThat(result).isEqualTo(Locale.FRANCE); }
@Test(expected = LocaleNotFoundException.class) public void testExtractFromAcceptNok() throws LocaleNotFoundException { instance.extractFromAccept("fr"); }
@Test(expected = LocaleNotFoundException.class) public void testExtractFromAcceptNok2() throws LocaleNotFoundException { instance.extractFromAccept(""); }