aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-04-27 11:01:38 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-04-27 17:09:58 +0200
commitb8e4a5f8a18bd99fb1a4c797907450ee4e02299a (patch)
treeb672ee98cb5c4747f9e7043cfb7dce06a6ab11f8
parent9b4f22fe343007c5692803b28ae13920e0212610 (diff)
downloadsonarqube-b8e4a5f8a18bd99fb1a4c797907450ee4e02299a.tar.gz
sonarqube-b8e4a5f8a18bd99fb1a4c797907450ee4e02299a.zip
use IllegalArgumentException in api/qualityprofiles/delete
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java12
2 files changed, 10 insertions, 9 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
index 63fdcda63c9..b8c110f7519 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
@@ -33,6 +33,7 @@ import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.user.UserSession;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
public class DeleteAction implements QProfileWsAction {
@@ -86,14 +87,12 @@ public class DeleteAction implements QProfileWsAction {
}
private static void ensureNoneIsMarkedAsDefault(QualityProfileDto profile, List<QualityProfileDto> descendants) {
- if (profile.isDefault()) {
- throw new IllegalStateException("Profile is marked as 'default' and cannot be deleted");
- }
+ checkArgument(!profile.isDefault(), "Profile '%s' cannot be deleted because it is marked as default", profile.getName());
descendants.stream()
.filter(QualityProfileDto::isDefault)
.findFirst()
.ifPresent(p -> {
- throw new IllegalStateException("Profile cannot be deleted because its descendant named [" + p.getName() + "] is marked as 'default'");
+ throw new IllegalArgumentException(String.format("Profile '%s' cannot be deleted because its descendant named '%s' is marked as default", profile.getName(), p.getName()));
});
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
index f680c9ca8dd..ce703582c62 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
@@ -243,8 +243,8 @@ public class DeleteActionTest {
QualityProfileDto profile = createDefaultProfile(organization);
logInAsQProfileAdministrator(organization);
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Profile is marked as 'default' and cannot be deleted");
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Profile '" + profile.getName() + "' cannot be deleted because it is marked as default");
tester.newRequest()
.setMethod("POST")
@@ -256,11 +256,13 @@ public class DeleteActionTest {
public void throw_ISE_if_a_descendant_is_marked_as_default() {
OrganizationDto organization = dbTester.organizations().insert();
QualityProfileDto parentProfile = createProfile(organization);
- QualityProfileDto childProfile = dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE), p -> p.setDefault(true), p -> p.setParentKee(parentProfile.getKey()));
+ QualityProfileDto childProfile = dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE), p -> p.setDefault(true),
+ p -> p.setParentKee(parentProfile.getKey()));
logInAsQProfileAdministrator(organization);
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Profile cannot be deleted because its descendant named [" + childProfile.getName() + "] is marked as 'default'");
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Profile '" + parentProfile.getName() + "' cannot be deleted because its descendant named '" + childProfile.getName() +
+ "' is marked as default");
tester.newRequest()
.setMethod("POST")