@Test void formatMentionFullName() { UserReference userReference = mock(UserReference.class); UserProperties userProperties = mock(UserProperties.class); DocumentReference documentReference = new DocumentReference("xwiki", "XWiki", "User"); when(this.userReferenceResolver.resolve("xwiki:XWiki.User")).thenReturn(userReference); when(this.userPropertiesResolver.resolve(userReference)).thenReturn(userProperties); when(this.documentReferenceResolver.resolve("xwiki:XWiki.User")).thenReturn(documentReference); when(userProperties.getFirstName()).thenReturn("First Name"); when(userProperties.getLastName()).thenReturn("Last Name"); String actual = this.formatter.formatMention("xwiki:XWiki.User", FULL_NAME); Assertions.assertEquals("@First Name Last Name", actual); }
@Override public String formatMention(String userReference, DisplayStyle style) { UserReference resolve = this.userReferenceResolver.resolve(userReference); UserProperties userProperties = this.userPropertiesResolver.resolve(resolve); String firstName = Objects.toString(userProperties.getFirstName(), ""); String lastName = Objects.toString(userProperties.getLastName(), ""); final String content; if (Objects.equals(style, LOGIN) || Objects.equals(firstName, "") && Objects.equals(lastName, "")) { content = this.documentReferenceResolver.resolve(userReference).getName(); } else if (Objects.equals(style, FIRST_NAME)) { content = firstName; } else { content = String.format("%s %s", firstName, lastName).trim(); } return "@" + content; }
DefaultMentionsFormatter implements MentionsFormatter { @Override public String formatMention(String userReference, DisplayStyle style) { UserReference resolve = this.userReferenceResolver.resolve(userReference); UserProperties userProperties = this.userPropertiesResolver.resolve(resolve); String firstName = Objects.toString(userProperties.getFirstName(), ""); String lastName = Objects.toString(userProperties.getLastName(), ""); final String content; if (Objects.equals(style, LOGIN) || Objects.equals(firstName, "") && Objects.equals(lastName, "")) { content = this.documentReferenceResolver.resolve(userReference).getName(); } else if (Objects.equals(style, FIRST_NAME)) { content = firstName; } else { content = String.format("%s %s", firstName, lastName).trim(); } return "@" + content; } }
DefaultMentionsFormatter implements MentionsFormatter { @Override public String formatMention(String userReference, DisplayStyle style) { UserReference resolve = this.userReferenceResolver.resolve(userReference); UserProperties userProperties = this.userPropertiesResolver.resolve(resolve); String firstName = Objects.toString(userProperties.getFirstName(), ""); String lastName = Objects.toString(userProperties.getLastName(), ""); final String content; if (Objects.equals(style, LOGIN) || Objects.equals(firstName, "") && Objects.equals(lastName, "")) { content = this.documentReferenceResolver.resolve(userReference).getName(); } else if (Objects.equals(style, FIRST_NAME)) { content = firstName; } else { content = String.format("%s %s", firstName, lastName).trim(); } return "@" + content; }  }
DefaultMentionsFormatter implements MentionsFormatter { @Override public String formatMention(String userReference, DisplayStyle style) { UserReference resolve = this.userReferenceResolver.resolve(userReference); UserProperties userProperties = this.userPropertiesResolver.resolve(resolve); String firstName = Objects.toString(userProperties.getFirstName(), ""); String lastName = Objects.toString(userProperties.getLastName(), ""); final String content; if (Objects.equals(style, LOGIN) || Objects.equals(firstName, "") && Objects.equals(lastName, "")) { content = this.documentReferenceResolver.resolve(userReference).getName(); } else if (Objects.equals(style, FIRST_NAME)) { content = firstName; } else { content = String.format("%s %s", firstName, lastName).trim(); } return "@" + content; }  @Override String formatMention(String userReference, DisplayStyle style); }
DefaultMentionsFormatter implements MentionsFormatter { @Override public String formatMention(String userReference, DisplayStyle style) { UserReference resolve = this.userReferenceResolver.resolve(userReference); UserProperties userProperties = this.userPropertiesResolver.resolve(resolve); String firstName = Objects.toString(userProperties.getFirstName(), ""); String lastName = Objects.toString(userProperties.getLastName(), ""); final String content; if (Objects.equals(style, LOGIN) || Objects.equals(firstName, "") && Objects.equals(lastName, "")) { content = this.documentReferenceResolver.resolve(userReference).getName(); } else if (Objects.equals(style, FIRST_NAME)) { content = firstName; } else { content = String.format("%s %s", firstName, lastName).trim(); } return "@" + content; }  @Override String formatMention(String userReference, DisplayStyle style);  }