2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.emailnotifications.newviolations;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.sonar.api.notifications.Notification;
25 import org.sonar.api.platform.EmailSettings;
26 import org.sonar.plugins.emailnotifications.api.EmailMessage;
28 import static org.hamcrest.Matchers.is;
29 import static org.hamcrest.Matchers.nullValue;
30 import static org.junit.Assert.assertThat;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 public class NewViolationsEmailTemplateTest {
36 private NewViolationsEmailTemplate template;
40 EmailSettings configuration = mock(EmailSettings.class);
41 when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
42 template = new NewViolationsEmailTemplate(configuration);
46 public void shouldNotFormatIfNotCorrectNotification() {
47 Notification notification = new Notification("other-notif");
48 EmailMessage message = template.format(notification);
49 assertThat(message, nullValue());
54 * Subject: New violations for project Foo
58 * 32 new violations introduced since 2012-01-02
60 * See it in Sonar: http://nemo.sonarsource.org/drilldown/measures/org.sonar.foo:foo?metric=new_violations&period=1
64 public void shouldFormatCommentAdded() {
65 Notification notification = new Notification("new-violations")
66 .setFieldValue("count", "32")
67 .setFieldValue("projectName", "Foo")
68 .setFieldValue("projectKey", "org.sonar.foo:foo")
69 .setFieldValue("projectId", "45")
70 .setFieldValue("fromDate", "2012-01-02");
72 EmailMessage message = template.format(notification);
73 assertThat(message.getMessageId(), is("new-violations/45"));
74 assertThat(message.getSubject(), is("New violations for project Foo"));
75 assertThat(message.getMessage(), is("" +
77 "32 new violations introduced since 2012-01-02\n" +
79 "See it in Sonar: http://nemo.sonarsource.org/drilldown/measures/org.sonar.foo:foo?metric=new_violations&period=1\n"));