.append("\n");
int newRules = profile.getNewRules();
if (newRules > 0) {
- message.append(" ").append(newRules).append(" new rules\n");
+ message.append(" ").append(newRules).append(" new rule")
+ .append(plural(newRules))
+ .append('\n');
}
int updatedRules = profile.getUpdatedRules();
if (updatedRules > 0) {
- message.append(" ").append(updatedRules).append(" rules have been updated\n");
+ message.append(" ").append(updatedRules).append(" rule")
+ .append(updatedRules > 1 ? "s have been updated" : " has been updated")
+ .append("\n");
}
int removedRules = profile.getRemovedRules();
if (removedRules > 0) {
- message.append(" ").append(removedRules).append(" rules removed\n");
+ message.append(" ").append(removedRules).append(" rule")
+ .append(plural(removedRules))
+ .append(" removed\n");
}
message.append("\n");
});
.setMessage(message.toString());
}
+ private static String plural(int count) {
+ return count > 1 ? "s" : "";
+ }
+
public String encode(String text) {
try {
return URLEncoder.encode(text, UTF_8.name());
}
@Test
- public void notification_contains_list_of_new_rules() {
+ public void notification_contains_count_of_new_rules() {
String profileName = newProfileName();
String languageKey = newLanguageKey();
String languageName = newLanguageName();
EmailMessage emailMessage = underTest.format(notification.serialize());
- assertMessage(emailMessage,
- "\n 2 new rules\n");
+ assertMessage(emailMessage, "\n 2 new rules\n");
}
@Test
- public void notification_contains_list_of_updated_rules() {
+ public void notification_contains_count_of_updated_rules() {
String profileName = newProfileName();
String languageKey = newLanguageKey();
String languageName = newLanguageName();
EmailMessage emailMessage = underTest.format(notification.serialize());
- assertMessage(emailMessage,
- "\n" +
- " 2 rules have been updated\n");
+ assertMessage(emailMessage, "\n 2 rules have been updated\n");
}
@Test
- public void notification_contains_list_of_removed_rules() {
+ public void notification_contains_count_of_removed_rules() {
String profileName = newProfileName();
String languageKey = newLanguageKey();
String languageName = newLanguageName();
EmailMessage emailMessage = underTest.format(notification.serialize());
- assertMessage(emailMessage,
- "\n" +
- " 2 rules removed\n");
+ assertMessage(emailMessage, "\n 2 rules removed\n");
+ }
+
+ @Test
+ public void notification_supports_grammar_for_single_rule_added_removed_or_updated() {
+ String profileName = newProfileName();
+ String languageKey = newLanguageKey();
+ String languageName = newLanguageName();
+ BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
+ .addProfile(Profile.newBuilder()
+ .setProfileName(profileName)
+ .setLanguageKey(languageKey)
+ .setLanguageName(languageName)
+ .setNewRules(1)
+ .setUpdatedRules(1)
+ .setRemovedRules(1)
+ .build());
+
+ EmailMessage emailMessage = underTest.format(notification.serialize());
+
+ assertThat(emailMessage.getMessage())
+ .contains("\n 1 new rule\n")
+ .contains("\n 1 rule has been updated\n")
+ .contains("\n 1 rule removed\n");
}
@Test
EmailMessage emailMessage = underTest.format(notification.serialize());
assertMessage(emailMessage,
- "\n" +
+ "\n" +
" 2 new rules\n" +
" 3 rules have been updated\n" +
" 4 rules removed\n");
assertThat(emailMessage.getMessage()).containsSequence("The following built-in profiles have been updated:\n",
profileTitleText(profileName1, languageKey1, languageName1),
- " 2 new rules\n",
- profileTitleText(profileName2, languageKey2, languageName2),
- " 13 new rules\n",
+ " 2 new rules\n",
+ profileTitleText(profileName2, languageKey2, languageName2),
+ " 13 new rules\n",
"This is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + server.getPublicRootUrl() + "/profiles");
}
}
private void assertMessage(EmailMessage emailMessage, String expectedProfileDetails) {
- assertThat(emailMessage.getMessage()).containsSequence("The following built-in profiles have been updated:\n\n",
- expectedProfileDetails,
- "\nThis is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + server.getPublicRootUrl() + "/profiles");
+ assertThat(emailMessage.getMessage())
+ .containsSequence(
+ "The following built-in profiles have been updated:\n\n",
+ expectedProfileDetails,
+ "\nThis is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + server.getPublicRootUrl() + "/profiles");
}
private String profileTitleText(String profileName, String languageKey, String languageName) {