aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java/org/sonar/api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-10 12:27:33 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-10 12:27:33 +0000
commit5cd839bbecd061d9463694d025788754bfca0f08 (patch)
tree6140b78f770fd0ab9654784e2068e80dadfb6345 /sonar-plugin-api/src/test/java/org/sonar/api
parent5c90df84c8d4c69c38868736bd28cb61f89d4b31 (diff)
downloadsonarqube-5cd839bbecd061d9463694d025788754bfca0f08.tar.gz
sonarqube-5cd839bbecd061d9463694d025788754bfca0f08.zip
simplify ValidationMessages and ProfileDefinition
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar/api')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java
new file mode 100644
index 00000000000..ea52c4c3c73
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java
@@ -0,0 +1,65 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.utils;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
+import static org.junit.internal.matchers.StringContains.containsString;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class ValidationMessagesTest {
+
+ @Test
+ public void emptyMessages() {
+ ValidationMessages messages = ValidationMessages.create();
+ assertThat(messages.hasErrors(), is(false));
+ assertThat(messages.hasWarnings(), is(false));
+ assertThat(messages.hasInfos(), is(false));
+
+ Logger logger = mock(Logger.class);
+ messages.log(logger);
+ verify(logger, never()).error(anyString());
+ verify(logger, never()).warn(anyString());
+ verify(logger, never()).info(anyString());
+ }
+
+ @Test
+ public void addError() {
+ ValidationMessages messages = ValidationMessages.create();
+ messages.addErrorText("my error");
+ assertThat(messages.hasErrors(), is(true));
+ assertThat(messages.hasWarnings(), is(false));
+ assertThat(messages.hasInfos(), is(false));
+ assertThat(messages.getErrors().size(), is(1));
+ assertThat(messages.getErrors(), hasItem("my error"));
+ assertThat(messages.toString(), containsString("my error"));
+
+ Logger logger = mock(Logger.class);
+ messages.log(logger);
+ verify(logger, times(1)).error("my error");
+ verify(logger, never()).warn(anyString());
+ verify(logger, never()).info(anyString());
+ }
+}