From c1096b3e7523a90ba9b3d2473dd95230727bd078 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 29 May 2015 19:43:14 +0200 Subject: [PATCH] SONAR-6568 missing unit test for QualityProfile --- .../qualityprofile/QualityProfileTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/qualityprofile/QualityProfileTest.java diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/qualityprofile/QualityProfileTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/qualityprofile/QualityProfileTest.java new file mode 100644 index 00000000000..d4ebfaaa834 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/qualityprofile/QualityProfileTest.java @@ -0,0 +1,72 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.computation.qualityprofile; + +import java.util.Date; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class QualityProfileTest { + + private static final String SOME_QP_KEY = "qpKey"; + private static final String SOME_QP_NAME = "qpName"; + private static final String SOME_LANGUAGE_KEY = "languageKey"; + private static final Date SOME_DATE = new Date(); + private static final QualityProfile QUALITY_PROFILE = new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE); + + @Test(expected = NullPointerException.class) + public void constructor_throws_NPE_if_qkKey_arg_is_null() { + new QualityProfile(null, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE); + } + + @Test(expected = NullPointerException.class) + public void constructor_throws_NPE_if_qpName_arg_is_null() { + new QualityProfile(SOME_QP_KEY, null, SOME_LANGUAGE_KEY, SOME_DATE); + } + + @Test(expected = NullPointerException.class) + public void constructor_throws_NPE_if_languageKey_arg_is_null() { + new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, null, SOME_DATE); + } + + @Test(expected = NullPointerException.class) + public void constructor_throws_NPE_if_rulesUpdatedAt_arg_is_null() { + new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, null); + } + + @Test + public void verify_properties() { + assertThat(QUALITY_PROFILE.getQpKey()).isEqualTo(SOME_QP_KEY); + assertThat(QUALITY_PROFILE.getQpName()).isEqualTo(SOME_QP_NAME); + assertThat(QUALITY_PROFILE.getLanguageKey()).isEqualTo(SOME_LANGUAGE_KEY); + assertThat(QUALITY_PROFILE.getRulesUpdatedAt()).isEqualTo(SOME_DATE); + } + + @Test + public void verify_getRulesUpdatedAt_keeps_object_immutable() { + assertThat(QUALITY_PROFILE.getRulesUpdatedAt()).isNotSameAs(SOME_DATE); + } + + @Test + public void verify_equals() { + assertThat(QUALITY_PROFILE).isEqualTo(new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)); + } +} \ No newline at end of file -- 2.39.5