aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-26 00:42:35 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-26 00:44:19 +0200
commit0d6868ad3bee64df7020d2b0a72b4dcdb90e0a3f (patch)
tree8f7306da99ecc6639ca9ce0d73c50e62d976faea /server
parent9b1ff9b09a407cca21bdc71f713d283c180aa5d3 (diff)
downloadsonarqube-0d6868ad3bee64df7020d2b0a72b4dcdb90e0a3f.tar.gz
sonarqube-0d6868ad3bee64df7020d2b0a72b4dcdb90e0a3f.zip
Fix potential test failure if CR-LF Git newline
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
index 2e78994ee4f..23490378746 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
@@ -20,6 +20,10 @@
package org.sonar.server.issue.notification;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
@@ -32,10 +36,6 @@ import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.server.user.index.UserDoc;
import org.sonar.server.user.index.UserIndex;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.Locale;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
@@ -95,7 +95,7 @@ public class MyNewIssuesEmailTemplateTest {
EmailMessage message = underTest.format(notification);
// TODO datetime to be completed when test is isolated from JVM timezone
- String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_all_details.txt"), StandardCharsets.UTF_8);
+ String file = loadTestFile("MyNewIssuesEmailTemplateTest/email_with_all_details.txt");
assertThat(message.getMessage()).startsWith(file);
}
@@ -124,7 +124,7 @@ public class MyNewIssuesEmailTemplateTest {
EmailMessage message = underTest.format(notification);
// TODO datetime to be completed when test is isolated from JVM timezone
- String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt"), StandardCharsets.UTF_8);
+ String file = loadTestFile("MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt");
assertThat(message.getMessage()).startsWith(file);
}
@@ -177,4 +177,10 @@ public class MyNewIssuesEmailTemplateTest {
.setFieldValue(RULE + ".2.label", "Rule the World (Java)")
.setFieldValue(RULE + ".2.count", "5");
}
+
+ private static String loadTestFile(String path) throws IOException {
+ String file = IOUtils.toString(MyNewIssuesEmailTemplateTest.class.getResource(path), StandardCharsets.UTF_8);
+ // sanitize EOL characters if git clone is badly configured
+ return file.replaceAll("\\r\\n|\\r", "");
+ }
}