LocaleHeaderDelegate implements RuntimeDelegate.HeaderDelegate<Locale> { @Override public String toString(Locale locale) { if (locale == null) { throw new IllegalArgumentException(); } String language = locale.getLanguage(); if (language.isEmpty() || "*".equals(language)) { return null; } String country = locale.getCountry(); if (country.isEmpty()) { return language.toLowerCase(); } return language.toLowerCase() + "-" + country.toLowerCase(); }  @Override Locale fromString(String header); @Override String toString(Locale locale);  }
@UseDataProvider("forTestToString") @Test public void testToString(Locale locale, String expectedResult) { String header = localeHeaderDelegate.toString(locale); assertEquals(expectedResult, header); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenLocaleIsNull() throws Exception { localeHeaderDelegate.toString(null); }