### Question:
ValidationController { Locale parseLocale(String locale) { Locale loc; String[] locs = locale.split("-"); if (locs.length > 2) { loc = new Locale(locs[0], locs[1], locs[2]); } else if (locs.length > 1) { loc = new Locale(locs[0], locs[1]); } else { loc = new Locale(locs[0]); } return loc; }  @Inject @Named("validationService") void setService(ValidationService validationService); @RequestMapping(value = "{canonicalClassName:.+}", method = RequestMethod.GET) ModelConstraint getConstraintsForClassName(@PathVariable String canonicalClassName, @RequestParam(required = false) String locale);  }### Answer:
@Test public void testEmptyLocale() { String loc = ""; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo(loc); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo(""); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo(""); }
@Test public void testLanguageLocale() { String loc = "fr"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo(loc); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo(""); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo(""); }
@Test public void testTrailingLanguageLocale() { String loc = "fr-"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo("fr"); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo(""); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo(""); }
@Test public void testLanguageCountryLocale() { String loc = "fr-FR"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo("fr"); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo("FR"); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo(""); }
@Test public void testTrailingLanguageCountryLocale() { String loc = "fr-FR-"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo("fr"); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo("FR"); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo(""); }
@Test public void testLanguageCountryVariantLocale() { String loc = "fr-FR-FR"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo("fr"); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo("FR"); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo("FR"); }
@Test public void testTrailingLanguageCountryVariantLocale() { String loc = "fr-FR-FR-"; Locale locale = this.validationController.parseLocale(loc); Assertions.assertThat(locale).isNotNull(); Assertions.assertThat(locale.getLanguage()).isNotNull().isEqualTo("fr"); Assertions.assertThat(locale.getCountry()).isNotNull().isEqualTo("FR"); Assertions.assertThat(locale.getVariant()).isNotNull().isEqualTo("FR"); }