diff options
author | David Gageot <david@gageot.net> | 2012-07-16 15:43:31 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-16 15:49:39 +0200 |
commit | 592cb1f45be74a17310ab7bb623c3e0e54dbea9f (patch) | |
tree | 2e466b7bcc9e145c0b065ba0021fa8a9924e103d /sonar-server | |
parent | a15e8577ff0f4b9e88cdf78e6aaed3ebd6259c50 (diff) | |
download | sonarqube-592cb1f45be74a17310ab7bb623c3e0e54dbea9f.tar.gz sonarqube-592cb1f45be74a17310ab7bb623c3e0e54dbea9f.zip |
Use ArgumentMatcher
Diffstat (limited to 'sonar-server')
5 files changed, 31 insertions, 39 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java index 5e91f5fe5b7..9468788be60 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java @@ -20,10 +20,9 @@ package org.sonar.server.configuration; import com.google.common.collect.ImmutableMap; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.CoreProperties; import org.sonar.api.database.configuration.Property; import org.sonar.jpa.test.AbstractDbUnitTestCase; @@ -35,7 +34,9 @@ import java.util.Map; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class PropertiesBackupTest extends AbstractDbUnitTestCase { @@ -77,14 +78,12 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase { backup.importXml(config); - verify(persistentSettings).saveProperties(argThat(new BaseMatcher<Map<String, String>>() { + verify(persistentSettings).saveProperties(argThat(new ArgumentMatcher<Map<String, String>>() { + @Override public boolean matches(Object o) { Map<String, String> map = (Map<String, String>) o; return map.get("key1").equals("value1") && map.get("key2").equals("value2"); } - - public void describeTo(Description description) { - } })); } @@ -98,14 +97,12 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase { config.setProperties(newProperties); backup.importXml(config); - verify(persistentSettings).saveProperties(argThat(new BaseMatcher<Map<String, String>>() { + verify(persistentSettings).saveProperties(argThat(new ArgumentMatcher<Map<String, String>>() { + @Override public boolean matches(Object o) { Map<String, String> map = (Map<String, String>) o; return map.get(CoreProperties.SERVER_ID).equals("111"); } - - public void describeTo(Description description) { - } })); } } diff --git a/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java index a4346e5866a..423041986b4 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/PersistentSettingsTest.java @@ -21,10 +21,9 @@ package org.sonar.server.platform; import com.google.common.collect.ImmutableMap; import org.apache.commons.configuration.PropertiesConfiguration; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.config.PropertyDefinitions; import org.sonar.core.properties.PropertiesDao; import org.sonar.core.properties.PropertyDto; @@ -35,7 +34,9 @@ import java.util.Arrays; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class PersistentSettingsTest { @@ -71,14 +72,12 @@ public class PersistentSettingsTest { // kept in memory cache and persisted in db assertThat(settings.getString("foo")).isEqualTo("bar"); - verify(dao).setProperty(argThat(new BaseMatcher<PropertyDto>() { + verify(dao).setProperty(argThat(new ArgumentMatcher<PropertyDto>() { + @Override public boolean matches(Object o) { PropertyDto dto = (PropertyDto) o; return dto.getKey().equals("foo"); } - - public void describeTo(Description description) { - } })); } diff --git a/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java b/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java index 05755d6661d..326fddda5c2 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java @@ -19,9 +19,8 @@ */ package org.sonar.server.platform; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.config.GlobalPropertyChangeHandler; import static org.fest.assertions.Assertions.assertThat; @@ -37,14 +36,12 @@ public class SettingsChangeNotifierTest { notifier.onGlobalPropertyChange("foo", "bar"); - verify(handler).onChange(argThat(new BaseMatcher<GlobalPropertyChangeHandler.PropertyChange>() { + verify(handler).onChange(argThat(new ArgumentMatcher<GlobalPropertyChangeHandler.PropertyChange>() { + @Override public boolean matches(Object o) { GlobalPropertyChangeHandler.PropertyChange change = (GlobalPropertyChangeHandler.PropertyChange) o; return change.getKey().equals("foo") && change.getNewValue().equals("bar"); } - - public void describeTo(Description description) { - } })); } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java b/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java index ba00c5c61cd..67dd9290b6c 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java @@ -19,11 +19,10 @@ */ package org.sonar.server.startup; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.CoreProperties; import org.sonar.api.platform.Server; import org.sonar.server.platform.PersistentSettings; @@ -35,7 +34,9 @@ import java.util.Map; import java.util.TimeZone; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ServerMetadataPersisterTest { @@ -65,7 +66,8 @@ public class ServerMetadataPersisterTest { ServerMetadataPersister persister = new ServerMetadataPersister(server, persistentSettings); persister.start(); - verify(persistentSettings).saveProperties(argThat(new BaseMatcher<Map<String, String>>() { + verify(persistentSettings).saveProperties(argThat(new ArgumentMatcher<Map<String, String>>() { + @Override public boolean matches(Object o) { Map<String, String> map = (Map<String, String>) o; return map.get(CoreProperties.SERVER_ID).equals("123") @@ -73,11 +75,7 @@ public class ServerMetadataPersisterTest { && map.get(CoreProperties.SERVER_STARTTIME).equals("2010-05-18T17:59:00+0000") && map.size() == 3; } - - public void describeTo(Description description) { - } })); } - } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java index 0f7ef2329f1..3b2cba14604 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java @@ -19,16 +19,19 @@ */ package org.sonar.server.startup; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.config.Settings; import org.sonar.server.platform.PersistentSettings; import java.util.Map; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class SetDefaultProjectPermissionsTest { @Test @@ -39,14 +42,12 @@ public class SetDefaultProjectPermissionsTest { new SetDefaultProjectPermissions(persistentSettings).start(); - verify(persistentSettings).saveProperties(argThat(new BaseMatcher<Map<String, String>>() { + verify(persistentSettings).saveProperties(argThat(new ArgumentMatcher<Map<String, String>>() { + @Override public boolean matches(Object o) { Map<String, String> map = (Map<String, String>) o; return map.size() == 9 && map.get("sonar.role.admin.TRK.defaultGroups").equals("sonar-administrators"); } - - public void describeTo(Description description) { - } })); } |