diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-03 21:50:16 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-03 21:57:31 +0100 |
commit | bb0bcf4dfb1eef2ff42655d5e00b5d62c7bc4a6e (patch) | |
tree | 169215a45203a91ac63222278c3064d1307cfd75 /sonar-server | |
parent | ee051c0da6dbc967b50eee86bd906f372ad4e8bf (diff) | |
download | sonarqube-bb0bcf4dfb1eef2ff42655d5e00b5d62c7bc4a6e.tar.gz sonarqube-bb0bcf4dfb1eef2ff42655d5e00b5d62c7bc4a6e.zip |
Remove some calls to commons-collections
Diffstat (limited to 'sonar-server')
5 files changed, 100 insertions, 109 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java index 42a3322d150..bef5e956544 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java @@ -25,7 +25,6 @@ import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseSession; @@ -89,7 +88,7 @@ public class ProfilesBackup implements Backupable { } public void importXml(SonarConfig sonarConfig) { - if (CollectionUtils.isNotEmpty(sonarConfig.getProfiles())) { + if (sonarConfig.getProfiles() != null && !sonarConfig.getProfiles().isEmpty()) { LoggerFactory.getLogger(getClass()).info("Delete profiles"); ProfilesManager profilesManager = new ProfilesManager(session, null); profilesManager.deleteAllProfiles(); @@ -118,7 +117,7 @@ public class ProfilesBackup implements Backupable { private void importAlerts(RulesProfile profile) { if (profile.getAlerts() != null) { - for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext();) { + for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext(); ) { Alert alert = ia.next(); Metric unMarshalledMetric = alert.getMetric(); String validKey = unMarshalledMetric.getKey(); @@ -135,20 +134,20 @@ public class ProfilesBackup implements Backupable { } private void importActiveRules(RulesDao rulesDao, RulesProfile profile) { - for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext();) { + for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext(); ) { ActiveRule activeRule = iar.next(); Rule unMarshalledRule = activeRule.getRule(); Rule matchingRuleInDb = rulesDao.getRuleByKey(unMarshalledRule.getRepositoryKey(), unMarshalledRule.getKey()); if (matchingRuleInDb == null) { LoggerFactory.getLogger(getClass()).error( - "Unable to find active rule " + unMarshalledRule.getRepositoryKey() + ":" + unMarshalledRule.getKey()); + "Unable to find active rule " + unMarshalledRule.getRepositoryKey() + ":" + unMarshalledRule.getKey()); iar.remove(); continue; } activeRule.setRule(matchingRuleInDb); activeRule.setRulesProfile(profile); activeRule.getActiveRuleParams(); - for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator(); irp.hasNext();) { + for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator(); irp.hasNext(); ) { ActiveRuleParam activeRuleParam = irp.next(); RuleParam unMarshalledRP = activeRuleParam.getRuleParam(); RuleParam matchingRPInDb = rulesDao.getRuleParam(matchingRuleInDb, unMarshalledRP.getKey()); @@ -180,7 +179,7 @@ public class ProfilesBackup implements Backupable { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map<String, String> values = readNode(reader); Alert alert = new Alert(null, new Metric(values.get("metric-key")), values.get("operator"), values.get("value-error"), - values.get("value-warning")); + values.get("value-warning")); String periodText = values.get("period"); if (StringUtils.isNotEmpty(periodText)) { alert.setPeriod(Integer.parseInt(periodText)); @@ -227,7 +226,7 @@ public class ProfilesBackup implements Backupable { reader.moveDown(); Map<String, String> valuesParam = readNode(reader); ActiveRuleParam activeRuleParam = new ActiveRuleParam(null, new RuleParam(null, valuesParam.get("key"), null, null), - valuesParam.get("value")); + valuesParam.get("value")); params.add(activeRuleParam); reader.moveUp(); } @@ -236,7 +235,7 @@ public class ProfilesBackup implements Backupable { } ActiveRule activeRule = new ActiveRule(null, new Rule(valuesRule.get("plugin"), valuesRule.get("key")), RulePriority - .valueOf(valuesRule.get("level"))); + .valueOf(valuesRule.get("level"))); activeRule.setActiveRuleParams(params); if (valuesRule.containsKey("inheritance")) { activeRule.setInheritance(valuesRule.get("inheritance")); diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java index 4aab263043a..2530f2230a7 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java @@ -22,7 +22,6 @@ package org.sonar.server.configuration; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.XStream; -import org.apache.commons.collections.CollectionUtils; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; import org.sonar.api.database.configuration.Property; @@ -43,7 +42,7 @@ public class PropertiesBackup implements Backupable { public void exportXml(SonarConfig sonarConfig) { List<Property> xmlProperties = Lists.newArrayList(); - for (PropertyDto property : persistentSettings.getGlobalProperties()){ + for (PropertyDto property : persistentSettings.getGlobalProperties()) { // "sonar.core.id" must never be restored, it is unique for a server and it created once at the 1rst server startup if (!CoreProperties.SERVER_ID.equals(property.getKey())) { xmlProperties.add(new Property(property.getKey(), property.getValue())); @@ -61,7 +60,7 @@ public class PropertiesBackup implements Backupable { String serverStartTime = persistentSettings.getString(CoreProperties.SERVER_STARTTIME); Map<String, String> properties = Maps.newHashMap(); - if (CollectionUtils.isNotEmpty(sonarConfig.getProperties())) { + if (sonarConfig.getProperties() != null && !sonarConfig.getProperties().isEmpty()) { for (Property xmlProperty : sonarConfig.getProperties()) { properties.put(xmlProperty.getKey(), xmlProperty.getValue()); } diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/RulesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/RulesBackup.java index df8a9d3a86d..60803e6b7c1 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/RulesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/RulesBackup.java @@ -26,7 +26,6 @@ import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import org.apache.commons.collections.CollectionUtils; import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseSession; import org.sonar.api.rules.Rule; @@ -34,7 +33,11 @@ import org.sonar.api.rules.RuleParam; import org.sonar.api.rules.RulePriority; import org.sonar.jpa.dao.RulesDao; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; public class RulesBackup implements Backupable { private Collection<Rule> rules; @@ -62,7 +65,7 @@ public class RulesBackup implements Backupable { public void importXml(SonarConfig sonarConfig) { disableUserRules(); - if (CollectionUtils.isNotEmpty(sonarConfig.getRules())) { + if (sonarConfig.getRules() != null && !sonarConfig.getRules().isEmpty()) { registerUserRules(sonarConfig.getRules()); } } @@ -95,7 +98,7 @@ public class RulesBackup implements Backupable { continue; } - for (Iterator<RuleParam> irp = rule.getParams().iterator(); irp.hasNext();) { + for (Iterator<RuleParam> irp = rule.getParams().iterator(); irp.hasNext(); ) { RuleParam param = irp.next(); RuleParam matchingRPInDb = rulesDao.getRuleParam(matchingParentRuleInDb, param.getKey()); if (matchingRPInDb == null) { @@ -106,8 +109,8 @@ public class RulesBackup implements Backupable { rule.setParent(matchingParentRuleInDb); Rule matchingRuleInDb = session.getSingleResult(Rule.class, - "pluginName", rule.getRepositoryKey(), - "key", rule.getKey()); + "pluginName", rule.getRepositoryKey(), + "key", rule.getKey()); if (matchingRuleInDb != null) { // merge matchingRuleInDb.setParent(matchingParentRuleInDb); @@ -163,8 +166,8 @@ public class RulesBackup implements Backupable { reader.moveDown(); Map<String, String> valuesParam = readNode(reader); rule.createParameter() - .setKey(valuesParam.get("key")) - .setDefaultValue(valuesParam.get("value")); + .setKey(valuesParam.get("key")) + .setDefaultValue(valuesParam.get("value")); reader.moveUp(); } } @@ -172,15 +175,15 @@ public class RulesBackup implements Backupable { } Rule parent = Rule.create() - .setRepositoryKey(valuesRule.get("parentRepositoryKey")) - .setKey(valuesRule.get("parentKey")); + .setRepositoryKey(valuesRule.get("parentRepositoryKey")) + .setKey(valuesRule.get("parentKey")); rule.setParent(parent) - .setRepositoryKey(valuesRule.get("repositoryKey")) - .setKey(valuesRule.get("key")) - .setConfigKey(valuesRule.get("configKey")) - .setName(valuesRule.get("name")) - .setDescription(valuesRule.get("description")) - .setSeverity(RulePriority.valueOf(valuesRule.get("level"))); + .setRepositoryKey(valuesRule.get("repositoryKey")) + .setKey(valuesRule.get("key")) + .setConfigKey(valuesRule.get("configKey")) + .setName(valuesRule.get("name")) + .setDescription(valuesRule.get("description")) + .setSeverity(RulePriority.valueOf(valuesRule.get("level"))); return rule; } diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java index bbb88cd7633..c49714c61da 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java @@ -20,7 +20,6 @@ package org.sonar.server.configuration; import com.google.common.collect.Lists; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.CharEncoding; import org.custommonkey.xmlunit.Diff; @@ -49,12 +48,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -74,7 +68,7 @@ public class BackupTest { @Test public void shouldReturnAValidXml() throws Exception { Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), - new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); + new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); SonarConfig sonarConfig = getSonarConfig(); sonarConfig.setMetrics(getMetrics()); sonarConfig.setProperties(getProperties()); @@ -108,100 +102,100 @@ public class BackupTest { @Test public void shouldImportXml() { Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), - new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); + new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); String xml = getFileFromClasspath("backup-restore-valid.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getMetrics(), getMetrics())); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), getProperties())); + assertThat(sonarConfig.getMetrics()).isEqualTo(getMetrics()); + assertThat(sonarConfig.getProperties()).isEqualTo(getProperties()); for (Metric metric : sonarConfig.getMetrics()) { - assertNotNull(metric.getEnabled()); - assertTrue(metric.getEnabled()); - assertNotNull(metric.getUserManaged()); - assertTrue(metric.getUserManaged()); + assertThat(metric.getEnabled()).isNotNull(); + assertThat(metric.getEnabled()).isTrue(); + assertThat(metric.getUserManaged()).isNotNull(); + assertThat(metric.getUserManaged()).isTrue(); } Collection<RulesProfile> profiles = sonarConfig.getProfiles(); - assertEquals(2, profiles.size()); + assertThat(profiles).hasSize(2); Iterator<RulesProfile> profilesIter = profiles.iterator(); RulesProfile testProfile = profilesIter.next(); - assertEquals("test name", testProfile.getName()); - assertEquals(true, testProfile.getDefaultProfile()); - assertEquals("test language", testProfile.getLanguage()); - assertEquals(1, testProfile.getActiveRules().size()); + assertThat("test name").isEqualTo(testProfile.getName()); + assertThat(testProfile.getDefaultProfile()).isTrue(); + assertThat("test language").isEqualTo(testProfile.getLanguage()); + assertThat(testProfile.getActiveRules()).hasSize(1); ActiveRule testActiveRule = testProfile.getActiveRules().get(0); - assertEquals(RulePriority.MAJOR, testActiveRule.getSeverity()); - assertNotNull(testActiveRule.getRule()); - assertEquals("test key", testActiveRule.getRule().getKey()); - assertEquals("test plugin", testActiveRule.getRule().getRepositoryKey()); - assertThat(testActiveRule.getInheritance(), nullValue()); - assertEquals(1, testActiveRule.getActiveRuleParams().size()); + assertThat(RulePriority.MAJOR).isEqualTo(testActiveRule.getSeverity()); + assertThat(testActiveRule.getRule()).isNotNull(); + assertThat("test key").isEqualTo(testActiveRule.getRule().getKey()); + assertThat("test plugin").isEqualTo(testActiveRule.getRule().getRepositoryKey()); + assertThat(testActiveRule.getInheritance()).isNull(); + assertThat(testActiveRule.getActiveRuleParams()).hasSize(1); ActiveRuleParam testActiveRuleParam = testActiveRule.getActiveRuleParams().get(0); - assertEquals("test value", testActiveRuleParam.getValue()); - assertNotNull(testActiveRuleParam.getRuleParam()); - assertEquals("test param key", testActiveRuleParam.getRuleParam().getKey()); + assertThat("test value").isEqualTo(testActiveRuleParam.getValue()); + assertThat(testActiveRuleParam.getRuleParam()).isNotNull(); + assertThat("test param key").isEqualTo(testActiveRuleParam.getRuleParam().getKey()); - assertEquals(2, testProfile.getAlerts().size()); + assertThat(testProfile.getAlerts()).hasSize(2); Alert testAlert = testProfile.getAlerts().get(0); - assertEquals(Alert.OPERATOR_GREATER, testAlert.getOperator()); - assertEquals("testError", testAlert.getValueError()); - assertEquals("testWarn", testAlert.getValueWarning()); - assertThat(testAlert.getPeriod(), nullValue()); - assertNotNull(testAlert.getMetric()); - assertEquals("test key", testAlert.getMetric().getKey()); + assertThat(Alert.OPERATOR_GREATER).isEqualTo(testAlert.getOperator()); + assertThat("testError").isEqualTo(testAlert.getValueError()); + assertThat("testWarn").isEqualTo(testAlert.getValueWarning()); + assertThat(testAlert.getPeriod()).isNull(); + assertThat(testAlert.getMetric()).isNotNull(); + assertThat("test key").isEqualTo(testAlert.getMetric().getKey()); Alert testAlert2 = testProfile.getAlerts().get(1); - assertEquals(Alert.OPERATOR_SMALLER, testAlert2.getOperator()); - assertEquals("testError2", testAlert2.getValueError()); - assertEquals("testWarn2", testAlert2.getValueWarning()); - assertThat(testAlert2.getPeriod(), is(1)); - assertNotNull(testAlert2.getMetric()); - assertEquals("test key2", testAlert2.getMetric().getKey()); + assertThat(Alert.OPERATOR_SMALLER).isEqualTo(testAlert2.getOperator()); + assertThat("testError2").isEqualTo(testAlert2.getValueError()); + assertThat("testWarn2").isEqualTo(testAlert2.getValueWarning()); + assertThat(testAlert2.getPeriod()).isEqualTo(1); + assertThat(testAlert2.getMetric()).isNotNull(); + assertThat("test key2").isEqualTo(testAlert2.getMetric().getKey()); // Child profile testProfile = profilesIter.next(); - assertEquals("test2 name", testProfile.getName()); - assertEquals("test name", testProfile.getParentName()); + assertThat("test2 name").isEqualTo(testProfile.getName()); + assertThat("test name").isEqualTo(testProfile.getParentName()); testActiveRule = testProfile.getActiveRules().get(0); - assertThat(testActiveRule.getInheritance(), is(ActiveRule.OVERRIDES)); + assertThat(testActiveRule.getInheritance()).isEqualTo(ActiveRule.OVERRIDES); Collection<Rule> rules = sonarConfig.getRules(); - assertThat(rules.size(), is(1)); + assertThat(rules).hasSize(1); Rule rule = rules.iterator().next(); - assertThat(rule.getParent().getRepositoryKey(), is("test plugin")); - assertThat(rule.getParent().getKey(), is("test key")); - assertThat(rule.getRepositoryKey(), is("test plugin")); - assertThat(rule.getKey(), is("test key2")); - assertThat(rule.getConfigKey(), is("test config key")); - assertThat(rule.getName(), is("test name")); - assertThat(rule.getDescription(), is("test description")); - assertThat(rule.getSeverity(), is(RulePriority.INFO)); - assertThat(rule.getParams().size(), is(1)); + assertThat(rule.getParent().getRepositoryKey()).isEqualTo("test plugin"); + assertThat(rule.getParent().getKey()).isEqualTo("test key"); + assertThat(rule.getRepositoryKey()).isEqualTo("test plugin"); + assertThat(rule.getKey()).isEqualTo("test key2"); + assertThat(rule.getConfigKey()).isEqualTo("test config key"); + assertThat(rule.getName()).isEqualTo("test name"); + assertThat(rule.getDescription()).isEqualTo("test description"); + assertThat(rule.getSeverity()).isEqualTo(RulePriority.INFO); + assertThat(rule.getParams()).hasSize(1); RuleParam param = rule.getParams().get(0); - assertThat(param.getKey(), is("test param key")); - assertThat(param.getDefaultValue(), is("test param value")); + assertThat(param.getKey()).isEqualTo("test param key"); + assertThat(param.getDefaultValue()).isEqualTo("test param value"); } @Test public void shouldImportXmlWithoutInheritanceInformation() { Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), - new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); + new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); String xml = getFileFromClasspath("backup-restore-without-inheritance.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); Collection<RulesProfile> profiles = sonarConfig.getProfiles(); - assertThat(profiles.size(), is(1)); + assertThat(profiles).hasSize(1); RulesProfile testProfile = profiles.iterator().next(); - assertThat(testProfile.getActiveRules().size(), is(1)); + assertThat(testProfile.getActiveRules()).hasSize(1); ActiveRule activeRule = testProfile.getActiveRules().get(0); - assertThat(activeRule.getInheritance(), nullValue()); + assertThat(activeRule.getInheritance()).isNull(); } @Test @@ -211,7 +205,7 @@ public class BackupTest { String xml = getFileFromClasspath("backup-with-cdata.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), getPropertiesWithXmlIlliciteCharacters())); + assertThat(sonarConfig.getProperties()).isEqualTo(getPropertiesWithXmlIlliciteCharacters()); } @Test @@ -221,9 +215,9 @@ public class BackupTest { String xml = getFileFromClasspath("shouldImportOneDotFiveFormat.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); - assertEquals(1, sonarConfig.getMetrics().size()); - assertTrue(CollectionUtils.isEmpty(sonarConfig.getProfiles())); - assertEquals(2, sonarConfig.getProperties().size()); + assertThat(sonarConfig.getMetrics()).hasSize(1); + assertThat(sonarConfig.getProfiles()).isNull(); + assertThat(sonarConfig.getProperties()).hasSize(2); } @Test @@ -233,7 +227,7 @@ public class BackupTest { String xml = getFileFromClasspath("backup-with-utf8-char.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), getPropertiesWithUtf8Characters())); + assertThat(sonarConfig.getProperties()).isEqualTo(getPropertiesWithUtf8Characters()); } @Test @@ -244,7 +238,7 @@ public class BackupTest { SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); Metric metric = sonarConfig.getMetrics().iterator().next(); - assertThat(metric.getId(), nullValue()); + assertThat(metric.getId()).isNull(); } @Test @@ -257,7 +251,7 @@ public class BackupTest { assertXmlAreSimilar(xml, "backup-with-splitted-cdata.xml"); sonarConfig = backup.getSonarConfigFromXml(xml); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), getPropertiesWithCDATA())); + assertThat(sonarConfig.getProperties()).isEqualTo(getPropertiesWithCDATA()); } private SonarConfig getSonarConfig() throws ParseException { @@ -319,10 +313,10 @@ public class BackupTest { List<Rule> rules = Lists.newArrayList(); Rule parentRule = Rule.create("test plugin", "test key", null); Rule rule = Rule.create("test plugin", "test key2", "test name") - .setDescription("test description") - .setConfigKey("test config key") - .setSeverity(RulePriority.INFO) - .setParent(parentRule); + .setDescription("test description") + .setConfigKey("test config key") + .setSeverity(RulePriority.INFO) + .setParent(parentRule); rule.createParameter().setKey("test param key").setDefaultValue("test param value"); rules.add(rule); return rules; @@ -360,7 +354,7 @@ public class BackupTest { try { XMLUnit.setIgnoreWhitespace(true); Diff diff = XMLUnit.compareXML(getFileFromClasspath(xmlExpected), xml); - assertTrue(diff.toString(), diff.similar()); + assertThat(diff.similar()).as(diff.toString()).isTrue(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java index 48298acb4d6..4af3e5db1b8 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.configuration; -import org.apache.commons.collections.CollectionUtils; import org.junit.Test; import org.sonar.jpa.dao.MeasuresDao; import org.sonar.jpa.test.AbstractDbUnitTestCase; @@ -28,10 +27,7 @@ import org.sonar.api.measures.Metric; import java.util.Arrays; import java.util.Collection; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - +import static org.fest.assertions.Assertions.assertThat; public class MetricsBackupTest extends AbstractDbUnitTestCase { @@ -42,7 +38,7 @@ public class MetricsBackupTest extends AbstractDbUnitTestCase { Collection<Metric> metrics = createMetrics(); metricsBackup.exportXml(sonarConfig, metrics); - assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getMetrics(), metrics)); + assertThat(sonarConfig.getMetrics()).isEqualTo(metrics); } @Test @@ -59,10 +55,10 @@ public class MetricsBackupTest extends AbstractDbUnitTestCase { metricsBackup.importXml(sonarConfig); Collection<Metric> allMetrics = measuresDao.getMetrics(); - assertThat(allMetrics.size(), is(4)); + assertThat(allMetrics).hasSize(4); Collection<Metric> enabledMetrics = measuresDao.getEnabledMetrics(); - assertThat(enabledMetrics.size(), is(3)); + assertThat(enabledMetrics).hasSize(3); } |