NotificationEmail: Fix eliding project name without slash

When a project name does not contain a slash, the name should not
be elided with "...".

Add extra tests that would have caught this.

Bug: Issue 10896
Change-Id: I131fa5c5016e758e8c6d7d2b09625fae6593da7b
This commit is contained in:
David Pursehouse
2019-05-22 09:44:36 +09:00
parent e003f87869
commit 8eece83e9a
2 changed files with 8 additions and 0 deletions

View File

@@ -132,6 +132,9 @@ public abstract class NotificationEmail extends OutgoingEmail {
if (lastIndexSlash == 0) {
return projectName.substring(1); // Remove the first slash
}
if (lastIndexSlash == -1) { // No slash in the project name
return projectName;
}
return "..." + projectName.substring(lastIndexSlash + 1);
}

View File

@@ -24,15 +24,20 @@ public class NotificationEmailTest {
@Test
public void instanceAndProjectName() throws Exception {
assertThat(getInstanceAndProjectName("test", "/my/api")).isEqualTo("test/api");
assertThat(getInstanceAndProjectName("test", "/api")).isEqualTo("test/api");
assertThat(getInstanceAndProjectName("test", "api")).isEqualTo("test/api");
}
@Test
public void instanceAndProjectNameNull() throws Exception {
assertThat(getInstanceAndProjectName(null, "/my/api")).isEqualTo("...api");
assertThat(getInstanceAndProjectName(null, "/api")).isEqualTo("api");
assertThat(getInstanceAndProjectName(null, "api")).isEqualTo("api");
}
@Test
public void shortProjectName() throws Exception {
assertThat(getShortProjectName("api")).isEqualTo("api");
assertThat(getShortProjectName("/api")).isEqualTo("api");
assertThat(getShortProjectName("/my/api")).isEqualTo("...api");
assertThat(getShortProjectName("/my/sub/project")).isEqualTo("...project");