@Test public void generateTest() { String givenNames = "Eva"; String surname = "Järvinen"; String acronym = acronymGenerator.generate(givenNames, surname); assertThat(acronym).isEqualTo("EVAJÄRVI"); }
@Override public String generate(String givenNames, String surname) { Assert.hasText(givenNames, "Given name is required"); Assert.hasText(surname, "Surname is required"); int wordsSize = 0; wordsSize += givenNames.length(); wordsSize += surname.length(); if (wordsSize < DEFAULT_SIZE) { return StringUtils.upperCase(new StringBuilder().append(givenNames).append(surname).toString()); } int fromGivenNames = 4; int fromSurname = 4; if (givenNames.length() < 4) { fromGivenNames = givenNames.length(); fromSurname += (4 - givenNames.length()); } if (surname.length() < 4) { fromSurname = surname.length(); fromGivenNames += (4 - surname.length()); } StringBuilder builder = new StringBuilder(); builder.append(givenNames.substring(0, fromGivenNames)); builder.append(surname.substring(0, fromSurname)); return StringUtils.upperCase(builder.toString()); }
AcronymGeneratorImpl implements AcronymGenerator { @Override public String generate(String givenNames, String surname) { Assert.hasText(givenNames, "Given name is required"); Assert.hasText(surname, "Surname is required"); int wordsSize = 0; wordsSize += givenNames.length(); wordsSize += surname.length(); if (wordsSize < DEFAULT_SIZE) { return StringUtils.upperCase(new StringBuilder().append(givenNames).append(surname).toString()); } int fromGivenNames = 4; int fromSurname = 4; if (givenNames.length() < 4) { fromGivenNames = givenNames.length(); fromSurname += (4 - givenNames.length()); } if (surname.length() < 4) { fromSurname = surname.length(); fromGivenNames += (4 - surname.length()); } StringBuilder builder = new StringBuilder(); builder.append(givenNames.substring(0, fromGivenNames)); builder.append(surname.substring(0, fromSurname)); return StringUtils.upperCase(builder.toString()); } }
AcronymGeneratorImpl implements AcronymGenerator { @Override public String generate(String givenNames, String surname) { Assert.hasText(givenNames, "Given name is required"); Assert.hasText(surname, "Surname is required"); int wordsSize = 0; wordsSize += givenNames.length(); wordsSize += surname.length(); if (wordsSize < DEFAULT_SIZE) { return StringUtils.upperCase(new StringBuilder().append(givenNames).append(surname).toString()); } int fromGivenNames = 4; int fromSurname = 4; if (givenNames.length() < 4) { fromGivenNames = givenNames.length(); fromSurname += (4 - givenNames.length()); } if (surname.length() < 4) { fromSurname = surname.length(); fromGivenNames += (4 - surname.length()); } StringBuilder builder = new StringBuilder(); builder.append(givenNames.substring(0, fromGivenNames)); builder.append(surname.substring(0, fromSurname)); return StringUtils.upperCase(builder.toString()); }  }
AcronymGeneratorImpl implements AcronymGenerator { @Override public String generate(String givenNames, String surname) { Assert.hasText(givenNames, "Given name is required"); Assert.hasText(surname, "Surname is required"); int wordsSize = 0; wordsSize += givenNames.length(); wordsSize += surname.length(); if (wordsSize < DEFAULT_SIZE) { return StringUtils.upperCase(new StringBuilder().append(givenNames).append(surname).toString()); } int fromGivenNames = 4; int fromSurname = 4; if (givenNames.length() < 4) { fromGivenNames = givenNames.length(); fromSurname += (4 - givenNames.length()); } if (surname.length() < 4) { fromSurname = surname.length(); fromGivenNames += (4 - surname.length()); } StringBuilder builder = new StringBuilder(); builder.append(givenNames.substring(0, fromGivenNames)); builder.append(surname.substring(0, fromSurname)); return StringUtils.upperCase(builder.toString()); }  @Override String generate(String givenNames, String surname); }
AcronymGeneratorImpl implements AcronymGenerator { @Override public String generate(String givenNames, String surname) { Assert.hasText(givenNames, "Given name is required"); Assert.hasText(surname, "Surname is required"); int wordsSize = 0; wordsSize += givenNames.length(); wordsSize += surname.length(); if (wordsSize < DEFAULT_SIZE) { return StringUtils.upperCase(new StringBuilder().append(givenNames).append(surname).toString()); } int fromGivenNames = 4; int fromSurname = 4; if (givenNames.length() < 4) { fromGivenNames = givenNames.length(); fromSurname += (4 - givenNames.length()); } if (surname.length() < 4) { fromSurname = surname.length(); fromGivenNames += (4 - surname.length()); } StringBuilder builder = new StringBuilder(); builder.append(givenNames.substring(0, fromGivenNames)); builder.append(surname.substring(0, fromSurname)); return StringUtils.upperCase(builder.toString()); }  @Override String generate(String givenNames, String surname);  }