]> source.dussan.org Git - sonarqube.git/commitdiff
Support build of SonarQube with JDK 9
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 23 Nov 2017 21:01:21 +0000 (22:01 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2017 21:01:21 +0000 (22:01 +0100)
65 files changed:
pom.xml
server/sonar-ce/pom.xml
server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
server/sonar-db-dao/pom.xml
server/sonar-db-dao/src/test/java/org/sonar/db/MyBatisTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java
server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java
server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/user/DeprecatedUserFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/user/UserSessionFilterTest.java
sonar-duplications/pom.xml
sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/TokenEntryTest.java
sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTest.java
sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java
sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java
sonar-duplications/src/test/java/org/sonar/duplications/block/ByteArrayTest.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/CloneGroupMatcher.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/ContainsInComparatorTest.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/original/FilterTest.java
sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java
sonar-duplications/src/test/java/org/sonar/duplications/index/DataUtilsTest.java
sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java
sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java
sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java
sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelDisptacherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/TokenMatcherFactoryTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/AnyTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/BridgeTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/ExactTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/ForgetLastTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/OptTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/statement/matcher/UptoTokenMatcherTest.java
sonar-duplications/src/test/java/org/sonar/duplications/token/TokenChannelTest.java
sonar-duplications/src/test/java/org/sonar/duplications/token/TokenQueueTest.java
sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java
sonar-duplications/src/test/java/org/sonar/duplications/utils/SortedListsUtilsTest.java
sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java
sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/utils/TimeProfilerTest.java
sonar-scanner-engine/pom.xml
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
sonar-testing-harness/pom.xml
sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java
sonar-testing-harness/src/test/java/org/sonar/test/i18n/I18nMatchersTest.java
tests/pom.xml
tests/src/test/java/org/sonarqube/tests/plugins/checks/JavascriptCheck.java
tests/src/test/java/org/sonarqube/tests/plugins/checks/Validation.java
tests/src/test/java/util/ItUtils.java

diff --git a/pom.xml b/pom.xml
index e73536e5ba0d63ebf0aba9f10621a84b73ea987c..22bc92c887b96d3438f2a664923dbf1f2e5b6189 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>jetty-server</artifactId>
         <version>${jetty.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.hamcrest</groupId>
+        <artifactId>hamcrest-core</artifactId>
+        <version>1.3</version>
+      </dependency>
       <dependency>
         <groupId>org.hamcrest</groupId>
         <artifactId>hamcrest-all</artifactId>
index 301c2cb31f41ef6bfcf41353a9705bd5ffc08469..42dc89d5de05fbffbce32c8324b6ee3a6c5fb05d 100644 (file)
       <artifactId>assertj-guava</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <!-- TODO to be removed -->
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
index 74b2a9503f7a4e929a2dd9a830c3f2b1097753d6..753928597ed97a2236e0c1d3a4c065489f5f66d3 100644 (file)
  */
 package org.sonar.ce.queue;
 
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.ce.container.ComputeEngineStatus.Status.STARTED;
-import static org.sonar.ce.container.ComputeEngineStatus.Status.STOPPING;
-
+import com.google.common.collect.ImmutableSet;
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.util.List;
 import java.util.Optional;
 import java.util.Random;
-
 import javax.annotation.Nullable;
-
-import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -59,7 +49,13 @@ import org.sonar.server.computation.task.step.TypedException;
 import org.sonar.server.organization.DefaultOrganization;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 
-import com.google.common.collect.ImmutableSet;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.ce.container.ComputeEngineStatus.Status.STARTED;
+import static org.sonar.ce.container.ComputeEngineStatus.Status.STOPPING;
 
 public class InternalCeQueueImplTest {
 
@@ -531,7 +527,7 @@ public class InternalCeQueueImplTest {
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
 
     expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(Matchers.startsWith("Task is in progress and can't be canceled"));
+    expectedException.expectMessage("Task is in progress and can't be canceled");
 
     underTest.cancel(db.getSession(), queueDto);
   }
index 8d308644fdd872c252fe553f48ca9a0b75fa2f22..f76bb60e10bda3483644c63bd315e60959d959a8 100644 (file)
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <!-- TODO to be removed -->
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.assertj</groupId>
       <artifactId>assertj-guava</artifactId>
index b86390171235b0a981fd68d55a8b03e100323077..999b160843efd1f86273a4bae69d1b15c63c7ea0 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.db.rule.RuleMapper;
 
-import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.junit.Assert.assertThat;
 
 public class MyBatisTest {
index 0295573904c71758ed4bd383d1e76f59f8ab873f..c163cb29b9dd13ac63270ba8d6768cbcea7b66bd 100644 (file)
@@ -157,7 +157,7 @@ public class AnalysisPropertiesDaoTest {
     assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(propertyDtos.size());
 
     List<AnalysisPropertyDto> result = underTest.selectBySnapshotUuid(dbSession, snapshotUuid);
-    assertThat(result).containsExactlyInAnyOrder((AnalysisPropertyDto[]) propertyDtos.toArray());
+    assertThat(result).containsExactlyInAnyOrder(propertyDtos.toArray(new AnalysisPropertyDto[0]));
   }
 
   private AnalysisPropertyDto insertAnalysisPropertyDto(int valueLength) {
index eb4a558fb171d730e27a0652fa7e50c622be1f9d..de60557946979bf15c3dd22938d23ce3ef593286 100644 (file)
@@ -23,9 +23,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class PurgeableAnalysisDtoTest {
   @Rule
@@ -35,18 +33,18 @@ public class PurgeableAnalysisDtoTest {
   public void testEquals() {
     PurgeableAnalysisDto dto1 = new PurgeableAnalysisDto().setAnalysisUuid("u3");
     PurgeableAnalysisDto dto2 = new PurgeableAnalysisDto().setAnalysisUuid("u4");
-    assertThat(dto1.equals(dto2), is(false));
-    assertThat(dto2.equals(dto1), is(false));
-    assertThat(dto1.equals(dto1), is(true));
-    assertThat(dto1.equals(new PurgeableAnalysisDto().setAnalysisUuid("u3")), is(true));
-    assertThat(dto1.equals("bi_bop_a_lou_la"), is(false));
-    assertThat(dto1.equals(null), is(false));
+    assertThat(dto1.equals(dto2)).isFalse();
+    assertThat(dto2.equals(dto1)).isFalse();
+    assertThat(dto1.equals(dto1)).isTrue();
+    assertThat(dto1.equals(new PurgeableAnalysisDto().setAnalysisUuid("u3"))).isTrue();
+    assertThat(dto1.equals("bi_bop_a_lou_la")).isFalse();
+    assertThat(dto1.equals(null)).isFalse();
   }
 
   @Test
   public void testHasCode() {
     PurgeableAnalysisDto dto = new PurgeableAnalysisDto().setAnalysisUuid("u3");
-    assertThat(dto.hashCode(), is(dto.hashCode()));
+    assertThat(dto.hashCode()).isEqualTo(dto.hashCode());
 
     // no uuid => NPE
     dto = new PurgeableAnalysisDto();
@@ -58,6 +56,6 @@ public class PurgeableAnalysisDtoTest {
   @Test
   public void testToString() {
     PurgeableAnalysisDto dto = new PurgeableAnalysisDto().setAnalysisUuid("u3");
-    assertThat(dto.toString().length(), greaterThan(0));
+    assertThat(dto.toString()).isNotEmpty();
   }
 }
index e49d5a9b784239b99ae7e629a671c1fcb20b4c5b..95da611ad5925394b1d10231d9af5d2b963e35da 100644 (file)
@@ -198,7 +198,7 @@ public class PermissionIndexerDao {
     if (projectUuids.isEmpty()) {
       sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", "");
     } else {
-      sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND (" + repeat("projects.uuid = ?", " or ", projectUuids.size()) + ")");
+      sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND projects.uuid in (" + repeat("?", ", ", projectUuids.size()) + ")");
     }
     PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
     int index = 1;
index 91d403e4d3771ad8cfa8d5875647ffdacfee2a4b..c7287a7058aaa1c6cf93767664ffc9653ac62962 100644 (file)
@@ -100,7 +100,7 @@ import org.hamcrest.CoreMatchers;
 import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 
-import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
index 5c9c31fd772d9b79c55ea8ab80cba0279f6b1c15..3d407a1477b7bbd1c6221aa78f9b9cd36cdd7930 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.mockito.Matchers;
+import org.mockito.Mockito;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.issue.IssueChangeContext;
 
-import static com.google.common.collect.Maps.newHashMap;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class AddTagsActionTest {
 
-  private AddTagsAction action;
-
-  private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class);
-
   @Rule
   public ExpectedException throwable = ExpectedException.none();
 
-  @Before
-  public void before() {
-    action = new AddTagsAction(issueUpdater);
-  }
+  private IssueFieldsSetter issueUpdater = new IssueFieldsSetter();
+  private AddTagsAction underTest = new AddTagsAction(issueUpdater);
 
   @Test
   @SuppressWarnings("unchecked")
   public void should_execute() {
-    Map<String, Object> properties = newHashMap();
+    Map<String, Object> properties = new HashMap<>();
     properties.put("tags", "tag2,tag3");
 
     DefaultIssue issue = mock(DefaultIssue.class);
     when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3"));
 
-    Action.Context context = mock(Action.Context.class);
+    Action.Context context = mock(Action.Context.class, Mockito.RETURNS_DEEP_STUBS);
     when(context.issue()).thenReturn(issue);
 
-    action.execute(properties, context);
-    verify(issueUpdater).setTags(eq(issue),
-      (Collection<String>) Matchers.argThat(org.hamcrest.Matchers.containsInAnyOrder("tag1", "tag2", "tag3")),
-      any(IssueChangeContext.class));
+    underTest.execute(properties, context);
+    verify(issue).setTags(ImmutableSet.of("tag1", "tag2", "tag3"));
   }
 
   @Test
@@ -74,7 +61,7 @@ public class AddTagsActionTest {
     throwable.expect(IllegalArgumentException.class);
     throwable.expectMessage("Tag 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
 
-    Map<String, Object> properties = newHashMap();
+    Map<String, Object> properties = new HashMap<>();
     properties.put("tags", "th ag");
 
     DefaultIssue issue = mock(DefaultIssue.class);
@@ -83,6 +70,6 @@ public class AddTagsActionTest {
     Action.Context context = mock(Action.Context.class);
     when(context.issue()).thenReturn(issue);
 
-    action.execute(properties, context);
+    underTest.execute(properties, context);
   }
 }
index fddefaa2f252a31377cb8fc9cffabb997767e460..c81a2fdc2e849c270f557801d10d1be4e7972b8b 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
 import java.util.Map;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.mockito.Matchers;
+import org.mockito.Mockito;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.issue.IssueChangeContext;
 
 import static com.google.common.collect.Maps.newHashMap;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class RemoveTagsActionTest {
 
-  private RemoveTagsAction action;
-
-  private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class);
-
   @Rule
   public ExpectedException throwable = ExpectedException.none();
 
-  @Before
-  public void before() {
-    action = new RemoveTagsAction(issueUpdater);
-  }
+  private IssueFieldsSetter issueUpdater = new IssueFieldsSetter();
+  private RemoveTagsAction action = new RemoveTagsAction(issueUpdater);
 
   @Test
   @SuppressWarnings("unchecked")
@@ -60,13 +49,11 @@ public class RemoveTagsActionTest {
     DefaultIssue issue = mock(DefaultIssue.class);
     when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3"));
 
-    Action.Context context = mock(Action.Context.class);
+    Action.Context context = mock(Action.Context.class, Mockito.RETURNS_DEEP_STUBS);
     when(context.issue()).thenReturn(issue);
 
     action.execute(properties, context);
-    verify(issueUpdater).setTags(eq(issue),
-      (Collection<String>) Matchers.argThat(org.hamcrest.Matchers.containsInAnyOrder("tag1")),
-      any(IssueChangeContext.class));
+    verify(issue).setTags(ImmutableSet.of("tag1"));
   }
 
   @Test
index 8b2f1bc150cdd1c39e457b9d87f13360f41bb354..fed6d37ab6dba5fe931c38f1276c630e522a31d1 100644 (file)
@@ -26,7 +26,7 @@ import org.mockito.MockitoAnnotations;
 import org.sonar.api.notifications.Notification;
 import org.sonar.api.notifications.NotificationChannel;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
index 0384a8f574703e204cc2efb2025592ea75a9e525..33fabe367f1bee1e81e801f36d3cf0d3ab1fdac4 100644 (file)
@@ -25,8 +25,8 @@ import org.sonar.api.config.EmailSettings;
 import org.sonar.api.notifications.Notification;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
index 32414882dc16b37ff8a0808d3835cb128f658e49..f967be7f1642161337bace8fc18d5725909b9e3d 100644 (file)
@@ -26,8 +26,8 @@ import org.sonar.api.database.model.User;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 
index 79ef9e2d898e2f7dcdedf00805237c2604481055..039d391c52919c95bf452906fdc6941f424825e2 100644 (file)
@@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InOrder;
-import org.mockito.Mockito;
+import org.sonar.core.platform.ComponentContainer;
 import org.sonar.db.DBSessions;
 import org.sonar.server.authentication.UserSessionInitializer;
 import org.sonar.server.organization.DefaultOrganizationCache;
@@ -48,7 +48,8 @@ import static org.mockito.Mockito.when;
 public class UserSessionFilterTest {
 
   private UserSessionInitializer userSessionInitializer = mock(UserSessionInitializer.class);
-  private Platform platform = mock(Platform.class, Mockito.RETURNS_DEEP_STUBS);
+  private ComponentContainer container = new ComponentContainer();
+  private Platform platform = mock(Platform.class);
   private HttpServletRequest request = mock(HttpServletRequest.class);
   private HttpServletResponse response = mock(HttpServletResponse.class);
   private FilterChain chain = mock(FilterChain.class);
@@ -59,9 +60,8 @@ public class UserSessionFilterTest {
 
   @Before
   public void setUp() {
-    when(platform.getContainer().getComponentByType(DBSessions.class)).thenReturn(dbSessions);
-    when(platform.getContainer().getComponentByType(ThreadLocalSettings.class)).thenReturn(settings);
-    when(platform.getContainer().getComponentByType(DefaultOrganizationCache.class)).thenReturn(defaultOrganizationCache);
+    container.add(dbSessions, settings, defaultOrganizationCache);
+    when(platform.getContainer()).thenReturn(container);
   }
 
   @Test
@@ -86,8 +86,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void does_nothing_when_not_initialized() throws Exception {
-    mockNoUserSessionInitializer();
-
     underTest.doFilter(request, response, chain);
 
     verify(chain).doFilter(request, response);
@@ -96,8 +94,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_loads_and_unloads_settings() throws Exception {
-    mockNoUserSessionInitializer();
-
     underTest.doFilter(request, response, chain);
 
     InOrder inOrder = inOrder(settings);
@@ -108,7 +104,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_unloads_Settings_even_if_chain_throws_exception() throws Exception {
-    mockNoUserSessionInitializer();
     RuntimeException thrown = mockChainDoFilterError();
 
     try {
@@ -122,8 +117,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_enables_and_disables_caching_in_DbSessions() throws Exception {
-    mockNoUserSessionInitializer();
-
     underTest.doFilter(request, response, chain);
 
     InOrder inOrder = inOrder(dbSessions);
@@ -134,7 +127,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_disables_caching_in_DbSessions_even_if_chain_throws_exception() throws Exception {
-    mockNoUserSessionInitializer();
     RuntimeException thrown = mockChainDoFilterError();
 
     try {
@@ -148,7 +140,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_unloads_Settings_even_if_DefaultOrganizationCache_unload_fails() throws Exception {
-    mockNoUserSessionInitializer();
     RuntimeException thrown = new RuntimeException("Faking DefaultOrganizationCache.unload failing");
     doThrow(thrown)
         .when(defaultOrganizationCache)
@@ -178,8 +169,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_loads_and_unloads_DefaultOrganizationCache() throws Exception {
-    mockNoUserSessionInitializer();
-
     underTest.doFilter(request, response, chain);
 
     InOrder inOrder = inOrder(defaultOrganizationCache);
@@ -190,7 +179,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_unloads_DefaultOrganizationCache_even_if_chain_throws_exception() throws Exception {
-    mockNoUserSessionInitializer();
     RuntimeException thrown = mockChainDoFilterError();
 
     try {
@@ -204,7 +192,6 @@ public class UserSessionFilterTest {
 
   @Test
   public void doFilter_unloads_DefaultOrganizationCache_even_if_Settings_unload_fails() throws Exception {
-    mockNoUserSessionInitializer();
     RuntimeException thrown = new RuntimeException("Faking Settings.unload failing");
     doThrow(thrown)
         .when(settings)
@@ -240,17 +227,13 @@ public class UserSessionFilterTest {
     // do not fail
   }
 
-  private void mockNoUserSessionInitializer() {
-    when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(null);
-  }
-
   private void mockUserSessionInitializer(boolean value) {
-    when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(userSessionInitializer);
+    container.add(userSessionInitializer);
     when(userSessionInitializer.initUserSession(request, response)).thenReturn(value);
   }
 
   private RuntimeException mockUserSessionInitializerRemoveUserSessionFailing() {
-    when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(userSessionInitializer);
+    container.add(userSessionInitializer);
     RuntimeException thrown = new RuntimeException("Faking UserSessionInitializer.removeUserSession failing");
     doThrow(thrown)
         .when(userSessionInitializer)
index 8d41b5acb8c285c134987a71bf4be4b3a82b543b..67ab7cc84881a69c7c0763a6e837a5f8d0b7252f 100644 (file)
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
index 950da090b89269849fb9c2cc6b3826b802e0c985..2d22ef7c6cb67db6eb802a2bcb0ee58f33b9bfcd 100644 (file)
@@ -22,8 +22,8 @@ package net.sourceforge.pmd.cpd;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertThat;
 
 public class TokenEntryTest {
index 41dd7677a2eccc5277216b4be4261264b0c41da2..27fbc5109582c1a4fc235c790f6480ffe6a0df28 100644 (file)
  */
 package org.sonar.duplications.block;
 
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
 import java.util.List;
-
 import org.junit.Test;
 import org.sonar.duplications.statement.Statement;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 public class BlockChunkerTest extends BlockChunkerTestCase {
 
   @Override
index 86716386be7b988a751902bd9f75a72a29fe47ae..9dfbb5eead605d7df32c414f6285ad0650bb0c6d 100644 (file)
@@ -25,10 +25,10 @@ import java.util.List;
 import org.junit.Test;
 import org.sonar.duplications.statement.Statement;
 
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertThat;
 
 /**
index 2d4a09573f66afa3c7d43f98376d58b283143d06..135dfad77f175b39fa93d0a791550b34b755cd47 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.duplications.block;
 
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertThat;
 
 public class BlockTest {
index c0844194124446d1f9bdac5a60acff0598d31552..eae430e70712c9d435b1fd416d9970e37ab25ea0 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.block;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import org.junit.Test;
index 499f5ede79c68ce7a1d41088ef1e5d0dc849b52a..3a58e443968f01f06f76f90d26e2b9c3514943fc 100644 (file)
@@ -25,7 +25,7 @@ import org.hamcrest.TypeSafeMatcher;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 
-import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItem;
 
 public class CloneGroupMatcher extends TypeSafeMatcher<CloneGroup> {
 
index c025a7ca2e71f78590bfe6ac11b62753d6653a35..ae2de81d32536485b4481c1b5f0ede282e51cf69 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.detector;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.*;
 
 import java.util.Comparator;
index ee3e8b32232b699ec61fc58716352291b424e280..dc3e9bdfc2a2f5d2a9e2af530a91defe147c7a6a 100644 (file)
@@ -34,8 +34,8 @@ import org.sonar.duplications.index.MemoryCloneIndex;
 import org.sonar.duplications.junit.TestNamePrinter;
 
 import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.spy;
index 68998fa87924743c7380fd1590fcba9f39f8e6a7..cee36b4620bb40cb817668d183445bfb2c4f0e76 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.duplications.detector.original;
 import org.junit.Test;
 import org.sonar.duplications.block.Block;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 public class BlocksGroupTest {
index 4b9af7f5c817c9de41818c7697236c7e129b615e..868bd4254c1a8f95d837d540c74e32c7c5822b77 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.duplications.index.ClonePart;
 
 import java.util.Arrays;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.*;
 
index 034a980b203a0f60e251288192110e1d5f9bad54..ff68df361e0fb28f9299355dd5d523c76bb7c269 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
index c73de4abe9e46696f6dfaa5e9e3cc0ee2503592c..1b6fd0285fe90c6a4b7cda572ce91ba2f040be3c 100644 (file)
@@ -19,8 +19,8 @@
  */
 package org.sonar.duplications.index;
 
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.util.Arrays;
index a96823135a426cd35afa67e7971ad2a91d236653..08d33c791e072dc8633db0bdb3d545ec16f85bcd 100644 (file)
@@ -30,8 +30,8 @@ import java.util.Collection;
 import java.util.Iterator;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertThat;
 
 public class PackedMemoryCloneIndexTest {
index f2cf7746e86cf44d22a29ff308b081cd1a680388..a60c7b423738f2976d38ad4c54974a0fa38975c0 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.duplications.block.ByteArray;
 import java.util.Arrays;
 import java.util.List;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 public class PmdBlockChunkerTest {
index f21a8195a837df18d1f8ecb08f1996cb27a902a6..db0c4929916de58bc7e03356d114a11167ceca77 100644 (file)
@@ -31,7 +31,7 @@ import net.sourceforge.pmd.cpd.Tokens;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 public class TokenizerBridgeTest {
index 4f02f68ba8399d8ccbf7d30da006062bc2981313..3bfd9dbaa052500b0da247fd42ad1bdf2d2627d6 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.duplications.token.TokenChunker;
 
 import static java.util.Arrays.asList;
 import static java.util.stream.Collectors.joining;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 /**
index 3ee629b73f9820712cb33bfb7e34f8d84b5319f8..8b309de477322795d33679c46700ccb506adc256 100644 (file)
@@ -26,22 +26,20 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import org.apache.commons.io.IOUtils;
-import org.hamcrest.Matcher;
-import org.hamcrest.Matchers;
 import org.junit.Test;
 import org.sonar.duplications.DuplicationsTestUtil;
 import org.sonar.duplications.token.Token;
 import org.sonar.duplications.token.TokenChunker;
 import org.sonar.duplications.token.TokenQueue;
 
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class JavaTokenProducerTest {
 
+  private static final Token NUMERIC_LITTERAL = new Token("$NUMBER", 1, 0);
+  private static final Token STRING_LITTERAL = new Token("$CHARS", 1, 0);
   private final TokenChunker chunker = JavaTokenProducer.build();
 
   /**
@@ -49,7 +47,7 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldIgnoreWhitespaces() {
-    assertThat(chunk(" \t\f\n\r"), isTokens());
+    assertThat(chunk(" \t\f\n\r")).isEmpty();
   }
 
   /**
@@ -57,15 +55,15 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldIgnoreEndOfLineComment() {
-    assertThat(chunk("// This is a comment"), isTokens());
-    assertThat(chunk("// This is a comment \n and_this_is_not"), isTokens(new Token("and_this_is_not", 2, 1)));
+    assertThat(chunk("// This is a comment")).isEmpty();
+    assertThat(chunk("// This is a comment \n and_this_is_not")).containsExactly(new Token("and_this_is_not", 2, 1));
   }
 
   @Test
   public void shouldIgnoreTraditionalComment() {
-    assertThat(chunk("/* This is a comment \n and the second line */"), isTokens());
-    assertThat(chunk("/** This is a javadoc \n and the second line */"), isTokens());
-    assertThat(chunk("/* this \n comment /* \n // /** ends \n here: */"), isTokens());
+    assertThat(chunk("/* This is a comment \n and the second line */")).isEmpty();
+    assertThat(chunk("/** This is a javadoc \n and the second line */")).isEmpty();
+    assertThat(chunk("/* this \n comment /* \n // /** ends \n here: */")).isEmpty();
   }
 
   /**
@@ -73,23 +71,24 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserveIdentifiers() {
-    assertThat(chunk("String"), isTokens(new Token("String", 1, 0)));
-    assertThat(chunk("i3"), isTokens(new Token("i3", 1, 0)));
-    assertThat(chunk("MAX_VALUE"), isTokens(new Token("MAX_VALUE", 1, 0)));
-    assertThat(chunk("isLetterOrDigit"), isTokens(new Token("isLetterOrDigit", 1, 0)));
+    assertThat(chunk("String")).containsExactly(new Token("String", 1, 0));
+    assertThat(chunk("i3")).containsExactly(new Token("i3", 1, 0));
+    assertThat(chunk("MAX_VALUE")).containsExactly(new Token("MAX_VALUE", 1, 0));
+    assertThat(chunk("isLetterOrDigit")).containsExactly(new Token("isLetterOrDigit", 1, 0));
 
-    assertThat(chunk("_"), isTokens(new Token("_", 1, 0)));
-    assertThat(chunk("_123_"), isTokens(new Token("_123_", 1, 0)));
-    assertThat(chunk("_Field"), isTokens(new Token("_Field", 1, 0)));
-    assertThat(chunk("_Field5"), isTokens(new Token("_Field5", 1, 0)));
+    assertThat(chunk("_")).containsExactly(new Token("_", 1, 0));
+    assertThat(chunk("_123_")).containsExactly(new Token("_123_", 1, 0));
+    assertThat(chunk("_Field")).containsExactly(new Token("_Field", 1, 0));
+    assertThat(chunk("_Field5")).containsExactly(new Token("_Field5", 1, 0));
 
-    assertThat(chunk("$"), isTokens(new Token("$", 1, 0)));
-    assertThat(chunk("$field"), isTokens(new Token("$field", 1, 0)));
+    assertThat(chunk("$")).containsExactly(new Token("$", 1, 0));
+    assertThat(chunk("$field")).containsExactly(new Token("$field", 1, 0));
 
-    assertThat(chunk("i2j"), isTokens(new Token("i2j", 1, 0)));
-    assertThat(chunk("from1to4"), isTokens(new Token("from1to4", 1, 0)));
+    assertThat(chunk("i2j")).containsExactly(new Token("i2j", 1, 0));
+    assertThat(chunk("from1to4")).containsExactly(new Token("from1to4", 1, 0));
 
-    assertThat("identifier with unicode", chunk("αβγ"), isTokens(new Token("αβγ", 1, 0)));
+    // identifier with unicode
+    assertThat(chunk("αβγ")).containsExactly(new Token("αβγ", 1, 0));
   }
 
   /**
@@ -97,7 +96,10 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserverKeywords() {
-    assertThat(chunk("private static final"), isTokens(new Token("private", 1, 0), new Token("static", 1, 8), new Token("final", 1, 15)));
+    assertThat(chunk("private static final")).containsExactly(
+      new Token("private", 1, 0),
+      new Token("static", 1, 8),
+      new Token("final", 1, 15));
   }
 
   /**
@@ -105,27 +107,27 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldNormalizeDecimalIntegerLiteral() {
-    assertThat(chunk("543"), isNumericLiteral());
-    assertThat(chunk("543l"), isNumericLiteral());
-    assertThat(chunk("543L"), isNumericLiteral());
+    assertThat(chunk("543")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("543l")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("543L")).containsExactly(NUMERIC_LITTERAL);
   }
 
   @Test
   public void shouldNormalizeOctalIntegerLiteral() {
-    assertThat(chunk("077"), isNumericLiteral());
-    assertThat(chunk("077l"), isNumericLiteral());
-    assertThat(chunk("077L"), isNumericLiteral());
+    assertThat(chunk("077")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("077l")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("077L")).containsExactly(NUMERIC_LITTERAL);
   }
 
   @Test
   public void shouldNormalizeHexIntegerLiteral() {
-    assertThat(chunk("0xFF"), isNumericLiteral());
-    assertThat(chunk("0xFFl"), isNumericLiteral());
-    assertThat(chunk("0xFFL"), isNumericLiteral());
+    assertThat(chunk("0xFF")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xFFl")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xFFL")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("0XFF"), isNumericLiteral());
-    assertThat(chunk("0XFFl"), isNumericLiteral());
-    assertThat(chunk("0XFFL"), isNumericLiteral());
+    assertThat(chunk("0XFF")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XFFl")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XFFL")).containsExactly(NUMERIC_LITTERAL);
   }
 
   /**
@@ -133,13 +135,13 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldNormalizeBinaryIntegerLiteral() {
-    assertThat(chunk("0b10"), isNumericLiteral());
-    assertThat(chunk("0b10l"), isNumericLiteral());
-    assertThat(chunk("0b10L"), isNumericLiteral());
+    assertThat(chunk("0b10")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0b10l")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0b10L")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("0B10"), isNumericLiteral());
-    assertThat(chunk("0B10l"), isNumericLiteral());
-    assertThat(chunk("0B10L"), isNumericLiteral());
+    assertThat(chunk("0B10")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0B10l")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0B10L")).containsExactly(NUMERIC_LITTERAL);
   }
 
   /**
@@ -148,72 +150,72 @@ public class JavaTokenProducerTest {
   @Test
   public void shouldNormalizeDecimalFloatingPointLiteral() {
     // with dot at the end
-    assertThat(chunk("1234."), isNumericLiteral());
-    assertThat(chunk("1234.E1"), isNumericLiteral());
-    assertThat(chunk("1234.e+1"), isNumericLiteral());
-    assertThat(chunk("1234.E-1"), isNumericLiteral());
-    assertThat(chunk("1234.f"), isNumericLiteral());
+    assertThat(chunk("1234.")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234.E1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234.e+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234.E-1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234.f")).containsExactly(NUMERIC_LITTERAL);
 
     // with dot between
-    assertThat(chunk("12.34"), isNumericLiteral());
-    assertThat(chunk("12.34E1"), isNumericLiteral());
-    assertThat(chunk("12.34e+1"), isNumericLiteral());
-    assertThat(chunk("12.34E-1"), isNumericLiteral());
+    assertThat(chunk("12.34")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34E1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34e+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34E-1")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("12.34f"), isNumericLiteral());
-    assertThat(chunk("12.34E1F"), isNumericLiteral());
-    assertThat(chunk("12.34E+1d"), isNumericLiteral());
-    assertThat(chunk("12.34e-1D"), isNumericLiteral());
+    assertThat(chunk("12.34f")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34E1F")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34E+1d")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("12.34e-1D")).containsExactly(NUMERIC_LITTERAL);
 
     // with dot at the beginning
-    assertThat(chunk(".1234"), isNumericLiteral());
-    assertThat(chunk(".1234e1"), isNumericLiteral());
-    assertThat(chunk(".1234E+1"), isNumericLiteral());
-    assertThat(chunk(".1234E-1"), isNumericLiteral());
+    assertThat(chunk(".1234")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234e1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234E+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234E-1")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk(".1234f"), isNumericLiteral());
-    assertThat(chunk(".1234E1F"), isNumericLiteral());
-    assertThat(chunk(".1234e+1d"), isNumericLiteral());
-    assertThat(chunk(".1234E-1D"), isNumericLiteral());
+    assertThat(chunk(".1234f")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234E1F")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234e+1d")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1234E-1D")).containsExactly(NUMERIC_LITTERAL);
 
     // without dot
-    assertThat(chunk("1234e1"), isNumericLiteral());
-    assertThat(chunk("1234E+1"), isNumericLiteral());
-    assertThat(chunk("1234E-1"), isNumericLiteral());
+    assertThat(chunk("1234e1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234E+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234E-1")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("1234E1f"), isNumericLiteral());
-    assertThat(chunk("1234e+1d"), isNumericLiteral());
-    assertThat(chunk("1234E-1D"), isNumericLiteral());
+    assertThat(chunk("1234E1f")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234e+1d")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1234E-1D")).containsExactly(NUMERIC_LITTERAL);
   }
 
   @Test
   public void shouldNormalizeHexadecimalFloatingPointLiteral() {
     // with dot at the end
-    assertThat(chunk("0xAF."), isNumericLiteral());
-    assertThat(chunk("0XAF.P1"), isNumericLiteral());
-    assertThat(chunk("0xAF.p+1"), isNumericLiteral());
-    assertThat(chunk("0XAF.p-1"), isNumericLiteral());
-    assertThat(chunk("0xAF.f"), isNumericLiteral());
+    assertThat(chunk("0xAF.")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAF.P1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAF.p+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAF.p-1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAF.f")).containsExactly(NUMERIC_LITTERAL);
 
     // with dot between
-    assertThat(chunk("0XAF.BC"), isNumericLiteral());
-    assertThat(chunk("0xAF.BCP1"), isNumericLiteral());
-    assertThat(chunk("0XAF.BCp+1"), isNumericLiteral());
-    assertThat(chunk("0xAF.BCP-1"), isNumericLiteral());
+    assertThat(chunk("0XAF.BC")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAF.BCP1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAF.BCp+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAF.BCP-1")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("0xAF.BCf"), isNumericLiteral());
-    assertThat(chunk("0xAF.BCp1F"), isNumericLiteral());
-    assertThat(chunk("0XAF.BCP+1d"), isNumericLiteral());
-    assertThat(chunk("0XAF.BCp-1D"), isNumericLiteral());
+    assertThat(chunk("0xAF.BCf")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAF.BCp1F")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAF.BCP+1d")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAF.BCp-1D")).containsExactly(NUMERIC_LITTERAL);
 
     // without dot
-    assertThat(chunk("0xAFp1"), isNumericLiteral());
-    assertThat(chunk("0XAFp+1"), isNumericLiteral());
-    assertThat(chunk("0xAFp-1"), isNumericLiteral());
+    assertThat(chunk("0xAFp1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAFp+1")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAFp-1")).containsExactly(NUMERIC_LITTERAL);
 
-    assertThat(chunk("0XAFp1f"), isNumericLiteral());
-    assertThat(chunk("0xAFp+1d"), isNumericLiteral());
-    assertThat(chunk("0XAFp-1D"), isNumericLiteral());
+    assertThat(chunk("0XAFp1f")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xAFp+1d")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0XAFp-1D")).containsExactly(NUMERIC_LITTERAL);
   }
 
   /**
@@ -221,19 +223,19 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldNormalizeNumericLiteralsWithUnderscores() {
-    assertThat(chunk("54_3L"), isNumericLiteral());
-    assertThat(chunk("07_7L"), isNumericLiteral());
-    assertThat(chunk("0b1_0L"), isNumericLiteral());
-    assertThat(chunk("0xF_FL"), isNumericLiteral());
-
-    assertThat(chunk("1_234."), isNumericLiteral());
-    assertThat(chunk("1_2.3_4"), isNumericLiteral());
-    assertThat(chunk(".1_234"), isNumericLiteral());
-    assertThat(chunk("1_234e1_0"), isNumericLiteral());
-
-    assertThat(chunk("0xA_F."), isNumericLiteral());
-    assertThat(chunk("0xA_F.B_C"), isNumericLiteral());
-    assertThat(chunk("0x1.ffff_ffff_ffff_fP1_023"), isNumericLiteral());
+    assertThat(chunk("54_3L")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("07_7L")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0b1_0L")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xF_FL")).containsExactly(NUMERIC_LITTERAL);
+
+    assertThat(chunk("1_234.")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1_2.3_4")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk(".1_234")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("1_234e1_0")).containsExactly(NUMERIC_LITTERAL);
+
+    assertThat(chunk("0xA_F.")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0xA_F.B_C")).containsExactly(NUMERIC_LITTERAL);
+    assertThat(chunk("0x1.ffff_ffff_ffff_fP1_023")).containsExactly(NUMERIC_LITTERAL);
   }
 
   /**
@@ -241,7 +243,7 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserveBooleanLiterals() {
-    assertThat(chunk("true false"), isTokens(new Token("true", 1, 0), new Token("false", 1, 5)));
+    assertThat(chunk("true false")).containsExactly(new Token("true", 1, 0), new Token("false", 1, 5));
   }
 
   /**
@@ -249,11 +251,16 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldNormalizeCharacterLiterals() {
-    assertThat("single character", chunk("'a'"), isStringLiteral());
-    assertThat("escaped LF", chunk("'\\n'"), isStringLiteral());
-    assertThat("escaped quote", chunk("'\\''"), isStringLiteral());
-    assertThat("octal escape", chunk("'\\177'"), isStringLiteral());
-    assertThat("unicode escape", chunk("'\\u03a9'"), isStringLiteral());
+    // single character
+    assertThat(chunk("'a'")).containsExactly(STRING_LITTERAL);
+    // escaped LF
+    assertThat(chunk("'\\n'")).containsExactly(STRING_LITTERAL);
+    // escaped quote
+    assertThat(chunk("'\\''")).containsExactly(STRING_LITTERAL);
+    // octal escape
+    assertThat(chunk("'\\177'")).containsExactly(STRING_LITTERAL);
+    // unicode escape
+    assertThat(chunk("'\\u03a9'")).containsExactly(STRING_LITTERAL);
   }
 
   /**
@@ -261,12 +268,18 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldNormalizeStringLiterals() {
-    assertThat("regular string", chunk("\"string\""), isStringLiteral());
-    assertThat("empty string", chunk("\"\""), isStringLiteral());
-    assertThat("escaped LF", chunk("\"\\n\""), isStringLiteral());
-    assertThat("escaped double quotes", chunk("\"string, which contains \\\"escaped double quotes\\\"\""), isStringLiteral());
-    assertThat("octal escape", chunk("\"string \\177\""), isStringLiteral());
-    assertThat("unicode escape", chunk("\"string \\u03a9\""), isStringLiteral());
+    // regular string
+    assertThat(chunk("\"string\"")).containsExactly(STRING_LITTERAL);
+    // empty string
+    assertThat(chunk("\"\"")).containsExactly(STRING_LITTERAL);
+    // escaped LF
+    assertThat(chunk("\"\\n\"")).containsExactly(STRING_LITTERAL);
+    // escaped double quotes
+    assertThat(chunk("\"string, which contains \\\"escaped double quotes\\\"\"")).containsExactly(STRING_LITTERAL);
+    // octal escape
+    assertThat(chunk("\"string \\177\"")).containsExactly(STRING_LITTERAL);
+    // unicode escape
+    assertThat(chunk("\"string \\u03a9\"")).containsExactly(STRING_LITTERAL);
   }
 
   /**
@@ -274,7 +287,7 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserverNullLiteral() {
-    assertThat(chunk("null"), isTokens(new Token("null", 1, 0)));
+    assertThat(chunk("null")).containsExactly(new Token("null", 1, 0));
   }
 
   /**
@@ -282,12 +295,12 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserveSeparators() {
-    assertThat(chunk("(){}[];,."), isTokens(
+    assertThat(chunk("(){}[];,.")).containsExactly(
       new Token("(", 1, 0), new Token(")", 1, 1),
       new Token("{", 1, 2), new Token("}", 1, 3),
       new Token("[", 1, 4), new Token("]", 1, 5),
       new Token(";", 1, 6), new Token(",", 1, 7),
-      new Token(".", 1, 8)));
+      new Token(".", 1, 8));
   }
 
   /**
@@ -295,17 +308,17 @@ public class JavaTokenProducerTest {
    */
   @Test
   public void shouldPreserveOperators() {
-    assertThat(chunk("+="), isTokens(new Token("+", 1, 0), new Token("=", 1, 1)));
-    assertThat(chunk("--"), isTokens(new Token("-", 1, 0), new Token("-", 1, 1)));
+    assertThat(chunk("+=")).containsExactly(new Token("+", 1, 0), new Token("=", 1, 1));
+    assertThat(chunk("--")).containsExactly(new Token("-", 1, 0), new Token("-", 1, 1));
   }
 
   @Test
   public void realExamples() {
     File testFile = DuplicationsTestUtil.findFile("/java/MessageResources.java");
-    assertThat(chunk(testFile).size(), Matchers.greaterThan(0));
+    assertThat(chunk(testFile)).isNotEmpty();
 
     testFile = DuplicationsTestUtil.findFile("/java/RequestUtils.java");
-    assertThat(chunk(testFile).size(), Matchers.greaterThan(0));
+    assertThat(chunk(testFile)).isNotEmpty();
   }
 
   private TokenQueue chunk(File file) {
@@ -320,21 +333,6 @@ public class JavaTokenProducerTest {
     }
   }
 
-  private static Matcher<List<Token>> isNumericLiteral() {
-    return isTokens(new Token("$NUMBER", 1, 0));
-  }
-
-  private static Matcher<List<Token>> isStringLiteral() {
-    return isTokens(new Token("$CHARS", 1, 0));
-  }
-
-  /**
-   * @return matcher for list of tokens
-   */
-  private static Matcher<List<Token>> isTokens(Token... tokens) {
-    return is(Arrays.asList(tokens));
-  }
-
   private List<Token> chunk(String sourceCode) {
     List<Token> target = new ArrayList<>();
     chunker.chunk(sourceCode).forEach(target::add);
index 0bc99930cfc1b80bbf71f9a31f46c18c624c1028..b710f2d00a2246098bcb2ca38b5290dbd1c9a057 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyListOf;
index 4bd873d4810b2956912cd8a35249812e3fbe1d15..d44d344445ee4195625fd64a9656682a88aea209 100644 (file)
  */
 package org.sonar.duplications.statement;
 
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.mockito.Matchers;
-
 import java.util.Arrays;
 import java.util.List;
-
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
 import org.sonar.duplications.statement.matcher.AnyTokenMatcher;
 import org.sonar.duplications.statement.matcher.TokenMatcher;
 import org.sonar.duplications.token.Token;
 import org.sonar.duplications.token.TokenQueue;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
 public class StatementChannelTest {
 
   @Test(expected = IllegalArgumentException.class)
index 961693106912d31c0f823aa03eb33568eaefc8e0..6b50fe3a45a22b436c82cf0c5805b496bdc865ab 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.util.ArrayList;
index 305af7d05d88331c758f60177cc562144931051f..e05a24c3b3af512d61434915ebeab41b1deb126f 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement;
 
-import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 
index 5443eba0f73c7a29e87fdd4fed63266ce12d2063..113928f37bccceb5d6096a8a714676f6b7616438 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement.matcher;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
index 89733e0f8ef73bbe8323c2ab36663dc7540ddfd8..32fa219c3cc56c7ed023d170b5544879a9c06236 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement.matcher;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
index 684b67a2f74bdf106377bac1ef8efc3cd6aeb3a2..bd4687fca2fc1c38db39694cbbd7babd56076884 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement.matcher;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
index a0746cbdd4f66b490458ba61c869c78259a04164..30f3540486433f797ab3071786f2b983de48059a 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.Test;
 import org.sonar.duplications.token.Token;
 import org.sonar.duplications.token.TokenQueue;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.spy;
index 9ffc1e0e78a7203076f06c33732fcd75dbec5a9c..4d33697782b5e6dbc6158630a75a50576b432fa9 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement.matcher;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
index 3e76a1b5b10be54e7fbf07f32cd502ca64768a1f..2e03a391a42dd77122589228389f696b81ce8cff 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.statement.matcher;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
index 08eb2f861d7ff4ab572e9dcfaf4038fd31fcd443..0d00b892be2dfbdd91967ad8606d2776fc72acc5 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.token;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
index 321235ca1ef7c2bd500d2852964b713cd1b98ab7..feee54254ca210437e1a1e36f93405ab8e16a770 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.token;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.util.ArrayList;
index 750cb0c7c5d63f881bb80c89a64e2aef57e96495..0111f0f76f56963969c8bb2cbee64edda78d3eb5 100644 (file)
@@ -23,8 +23,8 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertThat;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
 
 public class TokenTest {
 
index f1ba9d0cd4e6c54de5b796e74d34fa2676ad02fb..d7a6f8acf9a005bfe6d417ba847ba9283e300dd3 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.duplications.utils;
 
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.util.Arrays;
index 8ba22b82a070587972e0812a87d74f36687def12..1b103c6eec29e7df563efcf4fca7e8e3b92746ce 100644 (file)
@@ -3,8 +3,8 @@
  */
 package net.sourceforge.pmd.cpd.fork;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 import java.nio.charset.Charset;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java
deleted file mode 100644 (file)
index d72986e..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.api.test;
-
-import org.apache.commons.lang.ObjectUtils;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.resources.Resource;
-
-public class IsResource extends ArgumentMatcher<Resource> {
-
-  private String scope;
-  private String qualifier;
-  private String key;
-
-  public IsResource(String scope, String qualifier) {
-    this.scope = scope;
-    this.qualifier = qualifier;
-  }
-
-  public IsResource(String scope, String qualifier, String key) {
-    this(scope, qualifier);
-    this.key = key;
-  }
-
-  @Override
-  public boolean matches(Object o) {
-    Resource r = (Resource) o;
-    return ObjectUtils.equals(r.getScope(), scope) && ObjectUtils.equals(r.getQualifier(), qualifier) && r.getKey().equals(key);
-  }
-}
index ddc537947f558189ebfce5d786d07a5ed78e1997..71f09b96066d0f0d12b1c3fe5ea915f0ca607df4 100644 (file)
@@ -41,7 +41,7 @@ public class TimeProfilerTest {
     verify(logger).info(eq("{}..."), eq("Cycle analysis"));
 
     profiler.stop();
-    verify(logger).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyInt());
+    verify(logger).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyLong());
   }
 
   @Test
@@ -53,7 +53,7 @@ public class TimeProfilerTest {
     profiler.stop();
     profiler.stop();
     verify(logger, times(1)).info(anyString(), anyString()); // start() executes log() with 1 parameter
-    verify(logger, times(1)).info(anyString(), anyString(), anyInt()); // stop() executes log() with 3 parameters
+    verify(logger, times(1)).info(anyString(), anyString(), anyLong()); // stop() executes log() with 3 parameters
   }
 
   @Test
@@ -64,7 +64,7 @@ public class TimeProfilerTest {
     profiler.start("New task");
     profiler.stop();
     profiler.stop();
-    verify(logger, never()).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyInt());
-    verify(logger, times(1)).info(eq("{} done: {} ms"), eq("New task"), anyInt());
+    verify(logger, never()).info(eq("{} done: {} ms"), eq("Cycle analysis"), anyLong());
+    verify(logger, times(1)).info(eq("{} done: {} ms"), eq("New task"), anyLong());
   }
 }
index 086a9bec024da65e5fff6b5d8aa5ca9b42ef7025..f92d507858ea62980e6dc05c7b358b6aec895f11 100644 (file)
       <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>sonar-plugin-api</artifactId>
index 23c02f54f85936e4fc9af27e540605db5ad984af..b9468dd8056e585a7aaa304ac1bd7231d52a7961 100644 (file)
@@ -41,9 +41,8 @@ public class IgnoreIssuesFilter implements IssueFilter {
   public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
     if (hasMatchFor(issue)) {
       return false;
-    } else {
-      return chain.accept(issue);
     }
+    return chain.accept(issue);
   }
 
   private boolean hasMatchFor(FilterableIssue issue) {
index 60be7b5140e7866e409343848df9523685f14c52..6230c5ee925f85575b5203631f69c0eea329a93b 100644 (file)
@@ -53,9 +53,8 @@ public class QualityProfileProvider extends ProviderAdapter {
 
   @CheckForNull
   private static String getSonarProfile(AnalysisProperties props) {
-    String profile = null;
-    if (props.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
-      profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
+    String profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
+    if (profile != null) {
       LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
         + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
     }
index f3a47b46ec8aa4d840e8243e1beb2bfb68065585..93d0e829a6559dd5ee81ffdba48414a27087ca13 100644 (file)
@@ -32,8 +32,8 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.scanner.scan.measure.MeasureCache;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
index 5dc8a09e51135ce292ec1b08e6d545fc33040146..6753f155734323fc50a83a22653b7ca68a9777a5 100644 (file)
@@ -19,8 +19,8 @@
  */
 package org.sonar.scanner.issue.ignore;
 
-import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
@@ -35,32 +35,26 @@ import static org.mockito.Mockito.when;
 
 public class IgnoreIssuesFilterTest {
 
-  private PatternMatcher exclusionPatternMatcher;
-  private IgnoreIssuesFilter ignoreFilter;
-  private FilterableIssue issue;
-  private IssueFilterChain chain;
-
-  @Before
-  public void init() {
-    exclusionPatternMatcher = mock(PatternMatcher.class);
-    issue = mock(FilterableIssue.class);
-    chain = mock(IssueFilterChain.class);
-    when(chain.accept(issue)).thenReturn(true);
-
-    ignoreFilter = new IgnoreIssuesFilter(exclusionPatternMatcher);
-  }
+  private PatternMatcher exclusionPatternMatcher = mock(PatternMatcher.class);
+  private FilterableIssue issue = mock(FilterableIssue.class, Mockito.RETURNS_DEEP_STUBS);
+  private IssueFilterChain chain = mock(IssueFilterChain.class);
+  private IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(exclusionPatternMatcher);
 
   @Test
   public void shouldPassToChainIfMatcherHasNoPatternForIssue() {
-    when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class))).thenReturn(null);
-
-    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
+    when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class)))
+      .thenReturn(null);
+    when(chain.accept(issue)).thenReturn(true);
+    assertThat(underTest.accept(issue, chain)).isTrue();
   }
 
   @Test
-  public void shouldAcceptOrRefuseIfMatcherHasPatternForIssue() {
-    when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class))).thenReturn(mock(IssuePattern.class));
+  public void shouldRejectIfPatternMatches() {
+    IssuePattern pattern = mock(IssuePattern.class);
+    when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class)))
+      .thenReturn(pattern);
 
-    assertThat(ignoreFilter.accept(issue, chain)).isFalse();
+    assertThat(underTest.accept(issue, chain)).isFalse();
   }
+
 }
index 677cdfa53d743ad71c3f54f1c2f50f3c28ba2011..a479662cd20573eae8271ce4b0b7b0b8c3b4f401 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.scanner.mediumtest.log;
 
 import java.util.Collections;
 import java.util.Map;
+import org.hamcrest.CoreMatchers;
 import org.hamcrest.Description;
-import org.hamcrest.Matchers;
 import org.hamcrest.TypeSafeMatcher;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -64,7 +64,7 @@ public class ExceptionHandlingMediumTest {
     loader.withCause = false;
     thrown.expect(MessageException.class);
     thrown.expectMessage("Error loading settings");
-    thrown.expectCause(Matchers.nullValue(Throwable.class));
+    thrown.expectCause(CoreMatchers.nullValue(Throwable.class));
 
     batch.start();
   }
index 43a4ecbaaad865b9761c711503fde0eeae1012ef..137a2bcbd057078e5c128674d5e11d7e2b1cc62f 100644 (file)
@@ -39,7 +39,6 @@ import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNull;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
@@ -76,11 +75,11 @@ public class QualityProfileProviderTest {
 
   @Test
   public void testProvide() {
-    when(loader.load(eq("project"), isNull(String.class))).thenReturn(response);
+    when(loader.load("project", null)).thenReturn(response);
     ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
-    verify(loader).load(eq("project"), isNull(String.class));
+    verify(loader).load("project", null);
     verifyNoMoreInteractions(loader);
   }
 
@@ -88,6 +87,7 @@ public class QualityProfileProviderTest {
   public void testProjectDoesntExist() {
     when(projectRepo.exists()).thenReturn(false);
     when(loader.loadDefault(anyString())).thenReturn(response);
+    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
     ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
@@ -127,7 +127,6 @@ public class QualityProfileProviderTest {
   }
 
   private void assertResponse(ModuleQProfiles qps) {
-    assertThat(qps.findAll()).hasSize(1);
     assertThat(qps.findAll()).extracting("key").containsExactly("profile");
 
   }
index 51c36adc739354354fcbbbf8e5df38af53737619..5e663c4b57aad4d489a577d7ebbd0acffe8dc977 100644 (file)
@@ -36,6 +36,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class ModuleInputComponentStoreTest {
   @Rule
@@ -120,10 +121,12 @@ public class ModuleInputComponentStoreTest {
   public void should_find_module_components_with_non_global_strategy() {
     InputComponentStore inputComponentStore = mock(InputComponentStore.class);
     SensorStrategy strategy = new SensorStrategy();
-    ModuleInputComponentStore store = new ModuleInputComponentStore(mock(InputModule.class), inputComponentStore, strategy);
+    InputModule module = mock(InputModule.class);
+    when(module.key()).thenReturn("foo");
+    ModuleInputComponentStore store = new ModuleInputComponentStore(module, inputComponentStore, strategy);
 
     store.inputFiles();
-    verify(inputComponentStore).filesByModule(any(String.class));
+    verify(inputComponentStore).filesByModule("foo");
 
     String relativePath = "somepath";
     store.inputFile(relativePath);
index 1bfe094460e032a0097d2a71b627e6d8e08279ee..d340723c1e97c1375d0febd48e9de268952bb07f 100644 (file)
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-core</artifactId>
+    </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <scope>provided</scope>
     </dependency>
 
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.assertj</groupId>
       <artifactId>assertj-core</artifactId>
index 26dcd8690e1a055f38a5d06f515c21144dec1f32..562b0cccc38b4197e38ff7a72f9feab9d50fd05a 100644 (file)
@@ -32,7 +32,11 @@ import java.io.InputStream;
 import java.util.SortedMap;
 
 import static junit.framework.TestCase.fail;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.*;
 
 public class BundleSynchronizedMatcherTest {
index 149abda8f301a4c18737d65ef3c271138cb9e48a..5ea1701bbbbd9251558140eb063159c78129d95a 100644 (file)
@@ -23,7 +23,7 @@ import org.junit.Test;
 
 import java.io.File;
 
-import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
index c36c4aaee206cb00876b9fc59e5f4326f64a0e6f..535ee0bcc2a5ac895cf6b88c07db0c75a37fd77b 100644 (file)
@@ -83,8 +83,8 @@
       <artifactId>assertj-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-guava</artifactId>
     </dependency>
     <dependency>
       <groupId>com.googlecode.json-simple</groupId>
index 40f74d6494343a671231720820e4dafc4024f2b3..7fffd8550607710a43223d463c7a6a0a416884b9 100644 (file)
@@ -30,6 +30,6 @@ public class JavascriptCheck implements Check {
     validation.mustHaveComments(SRC_DIR);
     validation.mustHaveComplexity(SRC_DIR);
     validation.mustHaveIssues(SRC_DIR + "/HasIssues.js");
-    validation.mustHaveMeasuresGreaterThan(SRC_DIR + "/Person.js", 0, "coverage");
+    validation.mustHaveMeasuresGreaterThanOrEquals(SRC_DIR + "/Person.js", 0, "coverage");
   }
 }
index 9b2f9a4ea2165fc6cc6d0aa8d88231a7a3a1cafb..0c1a76dba739d1931242c79f9b1f994ce0470853 100644 (file)
@@ -22,18 +22,19 @@ package org.sonarqube.tests.plugins.checks;
 import com.google.common.base.Joiner;
 import com.google.gson.Gson;
 import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.plugins.Project;
 import java.io.File;
 import java.util.List;
 import java.util.Map;
-import org.hamcrest.Matchers;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
 import org.junit.rules.ErrorCollector;
+import org.sonarqube.tests.plugins.Project;
 import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.client.WsResponse;
 
 import static java.util.Arrays.asList;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
 import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
 import static util.ItUtils.newAdminWsClient;
 
@@ -57,22 +58,22 @@ public class Validation {
 
   public void mustHaveIssues(String path) {
     // TODO use the WS api/issues
-    mustHaveMeasuresGreaterThan(path, 1, "violations");
+    mustHaveMeasuresGreaterThanOrEquals(path, 1, "violations");
   }
 
   public void mustHaveComments(String path) {
-    mustHaveMeasuresGreaterThan(path, 0, "comment_lines", "comment_lines_density");
+    mustHaveMeasuresGreaterThanOrEquals(path, 0, "comment_lines", "comment_lines_density");
   }
 
   public void mustHaveComplexity(String path) {
-    mustHaveMeasuresGreaterThan(path, 0, "complexity");
+    mustHaveMeasuresGreaterThanOrEquals(path, 0, "complexity");
   }
 
   public void mustHaveSize(String path) {
-    mustHaveMeasuresGreaterThan(path, 0, "ncloc", "lines");
+    mustHaveMeasuresGreaterThanOrEquals(path, 0, "ncloc", "lines");
   }
 
-  public void mustHaveMeasuresGreaterThan(String path, int min, String... metricKeys) {
+  public void mustHaveMeasuresGreaterThanOrEquals(String path, int min, String... metricKeys) {
     for (String filePath : toFiles(path)) {
       fileMustHaveMeasures(filePath, metricKeys, min);
     }
@@ -87,7 +88,17 @@ public class Validation {
         Double measure = measures.get(metricKey);
         errorCollector.checkThat("Measure " + metricKey + " is set on file " + filePath, measure, notNullValue());
         if (measure != null) {
-          errorCollector.checkThat("Measure " + metricKey + " is positive on file " + filePath, measure.intValue(), Matchers.greaterThanOrEqualTo(min));
+          errorCollector.checkThat("Measure " + metricKey + " is positive on file " + filePath, measure.intValue(), new TypeSafeMatcher<Integer>() {
+            @Override
+            protected boolean matchesSafely(Integer item) {
+              return item >= min;
+            }
+
+            @Override
+            public void describeTo(Description description) {
+              description.appendText(metricKey).appendValue(min);
+            }
+          });
         }
       }
     }
@@ -111,7 +122,17 @@ public class Validation {
       errorCollector.checkThat("Source is set on file " + filePath, response.isSuccessful(), is(true));
       Sources source = Sources.parse(response.content());
       if (source != null) {
-        errorCollector.checkThat("Source is empty on file " + filePath, source.getSources().size(), Matchers.greaterThanOrEqualTo(minLines));
+        errorCollector.checkThat("Source is empty on file " + filePath, source.getSources().size(), new TypeSafeMatcher<Integer>() {
+          @Override
+          protected boolean matchesSafely(Integer item) {
+            return item >= minLines;
+          }
+
+          @Override
+          public void describeTo(Description description) {
+            description.appendValue(minLines);
+          }
+        });
       }
     }
   }
index f663c7d6b94b3331baf87c5a863a6048a7182fde..2e36b5731363de745992b8c6448f33c34ba4288c 100644 (file)
@@ -335,7 +335,7 @@ public class ItUtils {
 
   private static Stream<Measure> getStreamMeasures(Orchestrator orchestrator, String componentKey, String... metricKeys) {
     return newWsClient(orchestrator).measures().component(new ComponentWsRequest()
-      .setComponentKey(componentKey)
+      .setComponent(componentKey)
       .setMetricKeys(asList(metricKeys)))
       .getComponent().getMeasuresList()
       .stream();