From cba389dcee6ddd3d0cffd82d4c28beb87e53c58a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 21 Apr 2014 23:41:03 +0200 Subject: [PATCH] Continue move from hamcrest to fest-assert --- plugins/sonar-l10n-en-plugin/pom.xml | 14 +- sonar-application/pom.xml | 4 +- sonar-batch-maven-compat/pom.xml | 4 +- sonar-batch/pom.xml | 14 +- .../batch/phases/DecoratorsExecutorTest.java | 13 +- .../sonar/colorizer/CDocTokenizerTest.java | 13 +- .../CaseInsensitiveKeywordsTokenizerTest.java | 18 +- .../sonar/colorizer/CodeColorizerTest.java | 29 +- .../sonar/colorizer/HtmlCodeBuilderTest.java | 23 +- .../sonar/colorizer/HtmlDecoratorTest.java | 35 +-- .../org/sonar/colorizer/HtmlRendererTest.java | 22 +- .../JavaAnnotationTokenizerTest.java | 13 +- .../org/sonar/colorizer/JavaKeywordsTest.java | 11 +- .../sonar/colorizer/JavaTokenizersTest.java | 13 +- .../sonar/colorizer/JavadocTokenizerTest.java | 13 +- .../colorizer/KeywordsTokenizerTest.java | 18 +- .../sonar/colorizer/RegexpTokenizerTest.java | 19 +- .../colorizer/TokenizerDispatcherTest.java | 21 +- sonar-deprecated/pom.xml | 6 - .../org/sonar/api/resources/MethodTest.java | 2 +- .../org/sonar/api/rules/RuleUtilsTest.java | 23 +- .../DuplicationPredicatesTest.java | 9 +- .../block/BlockChunkerTestCase.java | 2 +- .../detector/DetectorTestCase.java | 132 +++++---- .../detector/original/BlocksGroupTest.java | 2 +- .../internal/pmd/TokenizerBridgeTest.java | 2 +- .../java/JavaDuplicationsFunctionalTest.java | 2 +- .../java/JavaStatementBuilderTest.java | 276 +++++++++--------- .../java/JavaTokenProducerTest.java | 2 +- .../statement/StatementChannelTest.java | 2 +- .../token/BlackHoleTokenChannelTest.java | 15 +- .../sonar/api/database/model/UserTest.java | 33 +-- .../sonar/api/utils/ManifestUtilsTest.java | 15 +- .../api/utils/ValidationMessagesTest.java | 30 +- .../utils/command/CommandExecutorTest.java | 2 +- sonar-server/pom.xml | 52 ++-- .../services/ServerSetupQueryTest.java | 9 +- .../ResourceUnmarshallerTest.java | 4 +- 38 files changed, 437 insertions(+), 480 deletions(-) diff --git a/plugins/sonar-l10n-en-plugin/pom.xml b/plugins/sonar-l10n-en-plugin/pom.xml index 58dfa5def13..4018b3a905e 100644 --- a/plugins/sonar-l10n-en-plugin/pom.xml +++ b/plugins/sonar-l10n-en-plugin/pom.xml @@ -25,7 +25,7 @@ org.codehaus.sonar sonar - 4.3-SNAPSHOT + 4.4-SNAPSHOT ../.. @@ -56,18 +56,6 @@ - - org.codehaus.mojo - native2ascii-maven-plugin - 1.0-beta-1 - - - - native2ascii - - - - org.codehaus.sonar sonar-packaging-maven-plugin diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 4c70ca1d0d4..60c410f9536 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -58,9 +58,9 @@ logback-core - ${pom.groupId} + ${project.groupId} sonar-batch-maven-compat - ${pom.version} + ${project.version} runtime diff --git a/sonar-batch-maven-compat/pom.xml b/sonar-batch-maven-compat/pom.xml index a19f029a522..b8a02ee6920 100644 --- a/sonar-batch-maven-compat/pom.xml +++ b/sonar-batch-maven-compat/pom.xml @@ -14,9 +14,9 @@ - ${pom.groupId} + ${project.groupId} sonar-batch - ${pom.version} + ${project.version} org.apache.maven diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml index 3d268b2f939..8e527478c01 100644 --- a/sonar-batch/pom.xml +++ b/sonar-batch/pom.xml @@ -111,8 +111,8 @@ test - org.mockito - mockito-all + org.easytesting + fest-assert test @@ -120,6 +120,16 @@ sonar-testing-harness test + + org.hamcrest + hamcrest-all + test + + + org.mockito + mockito-all + test + org.eclipse.jetty jetty-server diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java index a1118d316d7..3534236e503 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java @@ -32,11 +32,8 @@ import org.sonar.batch.DefaultDecoratorContext; import org.sonar.batch.events.EventBus; import org.sonar.core.measure.MeasurementFilters; -import static org.hamcrest.number.OrderingComparisons.greaterThanOrEqualTo; -import static org.hamcrest.number.OrderingComparisons.lessThan; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.containsString; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -54,11 +51,11 @@ public class DecoratorsExecutorTest { profiler.start(decorator2); profiler.stop(); - assertThat(profiler.getMessage().indexOf("Decorator1"), greaterThanOrEqualTo(0)); - assertThat(profiler.getMessage().indexOf("Decorator2"), greaterThanOrEqualTo(0)); + assertThat(profiler.getMessage().indexOf("Decorator1")).isGreaterThanOrEqualTo(0); + assertThat(profiler.getMessage().indexOf("Decorator2")).isGreaterThanOrEqualTo(0); // sequence of execution - assertThat(profiler.getMessage().indexOf("Decorator1"), lessThan(profiler.getMessage().indexOf("Decorator2"))); + assertThat(profiler.getMessage().indexOf("Decorator1")).isLessThan(profiler.getMessage().indexOf("Decorator2")); } @Test @@ -73,7 +70,7 @@ public class DecoratorsExecutorTest { fail("Exception has not been thrown"); } catch (SonarException e) { - assertThat(e.getMessage(), containsString("src/org/foo/Bar.java")); + assertThat(e.getMessage()).contains("src/org/foo/Bar.java"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/CDocTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/CDocTokenizerTest.java index a2436da7b72..7e2616ea209 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/CDocTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/CDocTokenizerTest.java @@ -23,10 +23,7 @@ import org.junit.Before; import org.junit.Test; import org.sonar.channel.CodeReader; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.fest.assertions.Assertions.assertThat; public class CDocTokenizerTest { @@ -40,10 +37,10 @@ public class CDocTokenizerTest { @Test public void testRead() { CDocTokenizer tokenizer = new CDocTokenizer("", ""); - assertTrue(tokenizer.consume(new CodeReader("//this is a comment"), codeBuilder)); - assertThat(codeBuilder.toString(), is("//this is a comment")); + assertThat(tokenizer.consume(new CodeReader("//this is a comment"), codeBuilder)).isTrue(); + assertThat(codeBuilder.toString()).isEqualTo("//this is a comment"); - assertFalse(tokenizer.consume(new CodeReader("this is not a comment"), codeBuilder)); - assertThat(codeBuilder.toString(), is("//this is a comment")); + assertThat(tokenizer.consume(new CodeReader("this is not a comment"), codeBuilder)).isFalse(); + assertThat(codeBuilder.toString()).isEqualTo("//this is a comment"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizerTest.java index 889241b0d06..ffb379c0637 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizerTest.java @@ -19,28 +19,26 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; -import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; - import org.junit.Test; +import static org.fest.assertions.Assertions.assertThat; +import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; + public class CaseInsensitiveKeywordsTokenizerTest { @Test public void hasNextToken() { CaseInsensitiveKeywordsTokenizer tokenizer = new CaseInsensitiveKeywordsTokenizer("", "", "PROCEDURE"); - assertThat(highlight("procedure name", tokenizer), is("procedure name")); - assertThat(highlight("Procedure name", tokenizer), is("Procedure name")); - assertThat(highlight("PROCEDURE name", tokenizer), is("PROCEDURE name")); + assertThat(highlight("procedure name", tokenizer)).isEqualTo("procedure name"); + assertThat(highlight("Procedure name", tokenizer)).isEqualTo("Procedure name"); + assertThat(highlight("PROCEDURE name", tokenizer)).isEqualTo("PROCEDURE name"); } @Test public void testClone() { CaseInsensitiveKeywordsTokenizer tokenizer = new CaseInsensitiveKeywordsTokenizer("", "", "PROCEDURE"); Tokenizer cloneTokenizer = tokenizer.clone(); - assertThat(tokenizer, is(not(cloneTokenizer))); - assertThat(highlight("procedure name", cloneTokenizer), is("procedure name")); + assertThat(tokenizer).isNotEqualTo(cloneTokenizer); + assertThat(highlight("procedure name", cloneTokenizer)).isEqualTo("procedure name"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java index 3c5860d3c82..b60d3d1b683 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/CodeColorizerTest.java @@ -33,12 +33,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; public class CodeColorizerTest { @@ -69,8 +64,8 @@ public class CodeColorizerTest { HtmlOptions options = new HtmlOptions(true, "my-table-id", false); String html = CodeColorizer.javaToHtml(java, options); - assertThat(html, containsString("> futures = Executors.newFixedThreadPool(threadCount).invokeAll(tasks); - assertThat(futures.size(), is(taskCount)); + assertThat(futures).hasSize(taskCount); // all html must be the same String html = futures.get(0).get(); for (Future future : futures) { - assertEquals(html, future.get()); + assertThat(html).isEqualTo(future.get()); } } @@ -131,10 +126,10 @@ public class CodeColorizerTest { assertHtml(html); assertContains(html, "
  /*
", - "
   * This method does <b>something</b>
", - "
   *
", - "
   * &lt;p&gt;description&lt;/p&gt;
", - "
   */
"); + "
   * This method does <b>something</b>
", + "
   *
", + "
   * &lt;p&gt;description&lt;/p&gt;
", + "
   */
"); } /** @@ -161,7 +156,7 @@ public class CodeColorizerTest { private void assertContains(String html, String... strings) { for (String string : strings) { - assertThat(html, containsString(string)); + assertThat(html).contains(string); } } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlCodeBuilderTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlCodeBuilderTest.java index 42ec296b0db..60b5880e0ee 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlCodeBuilderTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlCodeBuilderTest.java @@ -22,10 +22,7 @@ package org.sonar.colorizer; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; public class HtmlCodeBuilderTest { @@ -39,7 +36,7 @@ public class HtmlCodeBuilderTest { @Test public void testAppendCharSequence() { builder.append("freddy < olivier"); - assertEquals("freddy < olivier", builder.toString()); + assertThat("freddy < olivier").isEqualTo(builder.toString()); } @Test @@ -47,35 +44,35 @@ public class HtmlCodeBuilderTest { builder.append('p'); builder.append('a'); builder.append('>'); - assertEquals("pa>", builder.toString()); + assertThat("pa>").isEqualTo(builder.toString()); } @Test public void testAppendCharSequenceIntInt() { builder.append("freddy < olivier", 0, 2); - assertEquals("fr", builder.toString()); + assertThat("fr").isEqualTo(builder.toString()); } @Test public void testAppendWithoutTransforming() { builder.appendWithoutTransforming("outside"); - assertEquals("outside", builder.toString()); + assertThat("outside").isEqualTo(builder.toString()); } @Test public void testStatefulVariables() { - assertThat(builder.getVariable("foo"), nullValue()); + assertThat(builder.getVariable("foo")).isNull(); builder.setVariable("foo", "xxx"); - assertThat((String) builder.getVariable("foo"), is("xxx")); + assertThat((String) builder.getVariable("foo")).isEqualTo(("xxx")); builder.setVariable("foo", "yyy"); - assertThat((String) builder.getVariable("foo"), is("yyy")); + assertThat((String) builder.getVariable("foo")).isEqualTo(("yyy")); builder.setVariable("foo", null); - assertThat(builder.getVariable("foo"), nullValue()); + assertThat(builder.getVariable("foo")).isNull(); - assertThat((String) builder.getVariable("foo", "default"), is("default")); + assertThat((String) builder.getVariable("foo", "default")).isEqualTo(("default")); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java index eea8b1b580a..00919dfcd7c 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlDecoratorTest.java @@ -19,15 +19,11 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.StringContains.containsString; - import org.junit.Test; import org.sonar.channel.CodeReader; +import static org.fest.assertions.Assertions.assertThat; + public class HtmlDecoratorTest { @Test @@ -84,34 +80,35 @@ public class HtmlDecoratorTest { HtmlCodeBuilder output = new HtmlCodeBuilder(); output.appendWithoutTransforming(decorator.getTagBeginOfFile()); - assertThat(decorator.consume(code, output), is(true)); - assertThat(decorator.consume(code, output), is(true)); - assertThat(decorator.consume(code, output), is(true)); + assertThat(decorator.consume(code, output)).isTrue(); + assertThat(decorator.consume(code, output)).isTrue(); + assertThat(decorator.consume(code, output)).isTrue(); output.appendWithoutTransforming(decorator.getTagEndOfFile()); - - assertThat(output.toString(), is( - "
" - + "" - + "" + + assertThat(output.toString()).isEqualTo( + "
" + + "" + + "" + "" - + "
")); + + "" + ); } @Test public void getCss() { - assertThat(HtmlDecorator.getCss().length(), greaterThan(100)); - assertThat(HtmlDecorator.getCss(), containsString(".code")); + assertThat(HtmlDecorator.getCss().length()).isGreaterThan(100); + assertThat(HtmlDecorator.getCss()).contains(".code"); } public void assertContains(String html, String... strings) { for (String string : strings) { - assertThat(html, containsString(string)); + assertThat(html).contains(string); } } public void assertNotContains(String html, String... strings) { for (String string : strings) { - assertThat(html, not(containsString(string))); + assertThat(html).doesNotContain(string); } } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java index 74d9bc69476..b3176402377 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlRendererTest.java @@ -28,9 +28,7 @@ import java.io.IOException; import java.io.StringReader; import java.util.Arrays; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.StringContains.containsString; +import static org.fest.assertions.Assertions.assertThat; public class HtmlRendererTest { @@ -42,7 +40,7 @@ public class HtmlRendererTest { String html = htmlRenderer.render(new StringReader("public class Hello {"), Arrays.asList(javaKeywordTokenizer)); - assertThat(html, is("public class Hello {")); + assertThat(html).isEqualTo("public class Hello {"); } @Test @@ -51,7 +49,7 @@ public class HtmlRendererTest { String html = htmlRenderer.render(new StringReader("foo(\"\");"), Arrays.asList(new LiteralTokenizer("", ""))); - assertThat(html, is("foo(\"<html>\");")); + assertThat(html).isEqualTo("foo(\"<html>\");"); } @Test @@ -60,13 +58,13 @@ public class HtmlRendererTest { String html = new HtmlRenderer().render(new FileReader(java), Arrays.asList(javaKeywordTokenizer)); - assertThat(html, containsString("")); - assertThat(html, containsString("")); + assertThat(html).contains(""); + assertThat(html).contains(""); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaAnnotationTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaAnnotationTokenizerTest.java index 26ad9eb3ed4..0e6ced24860 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaAnnotationTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaAnnotationTokenizerTest.java @@ -19,24 +19,23 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; - import org.junit.Test; +import static org.fest.assertions.Assertions.assertThat; +import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; + public class JavaAnnotationTokenizerTest { JavaAnnotationTokenizer tokenizer = new JavaAnnotationTokenizer("", ""); @Test public void testHighlighting() { - assertThat(highlight("@deprecated public", tokenizer), is("@deprecated public")); - assertThat(highlight("import", tokenizer), is("import")); + assertThat(highlight("@deprecated public", tokenizer)).isEqualTo("@deprecated public"); + assertThat(highlight("import", tokenizer)).isEqualTo("import"); } @Test public void testHighlightingWithProperties() { - assertThat(highlight("@Target(ElementType.METHOD)", tokenizer), is("@Target(ElementType.METHOD)")); + assertThat(highlight("@Target(ElementType.METHOD)", tokenizer)).isEqualTo("@Target(ElementType.METHOD)"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaKeywordsTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaKeywordsTest.java index dbab1f20a06..90fd7a22731 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaKeywordsTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaKeywordsTest.java @@ -19,18 +19,15 @@ */ package org.sonar.colorizer; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; import org.junit.Test; -import static org.junit.internal.matchers.IsCollectionContaining.hasItem; + +import static org.fest.assertions.Assertions.assertThat; public class JavaKeywordsTest { @Test public void get() { - assertThat(JavaKeywords.get().size(), is(53)); - assertThat(JavaKeywords.get(), hasItem("true")); - assertThat(JavaKeywords.get(), hasItem("public")); - assertThat(JavaKeywords.get(), hasItem("switch")); + assertThat(JavaKeywords.get()).hasSize(53); + assertThat(JavaKeywords.get()).contains("true", "public", "switch"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaTokenizersTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaTokenizersTest.java index 98e9706186d..01527269a29 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaTokenizersTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavaTokenizersTest.java @@ -23,24 +23,21 @@ import java.util.List; import org.junit.Test; -import static junit.framework.Assert.fail; - -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.hamcrest.number.OrderingComparisons.lessThan; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.fail; public class JavaTokenizersTest { @Test public void forHtml() { - assertThat(JavaTokenizers.forHtml().size(), greaterThan(3)); + assertThat(JavaTokenizers.forHtml().size()).isGreaterThan(3); } @Test public void javadocIsDefinedBeforeCppComment() { // just because /** must be detected before /* - assertThat(indexOf(JavaTokenizers.forHtml(), JavadocTokenizer.class), - lessThan(indexOf(JavaTokenizers.forHtml(), CppDocTokenizer.class))); + assertThat(indexOf(JavaTokenizers.forHtml(), JavadocTokenizer.class)).isLessThan( + indexOf(JavaTokenizers.forHtml(), CppDocTokenizer.class)); } private Integer indexOf(List tokenizers, Class tokenizerClass) { diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavadocTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavadocTokenizerTest.java index 0474a6ceff5..809c27794ff 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/JavadocTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/JavadocTokenizerTest.java @@ -19,24 +19,23 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; - import org.junit.Test; +import static org.fest.assertions.Assertions.assertThat; +import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; + public class JavadocTokenizerTest { JavadocTokenizer tokenizer = new JavadocTokenizer("", ""); @Test public void testHighlighting() { - assertThat(highlight("/**this is a javadoc*/ public ...", tokenizer), is("/**this is a javadoc*/ public ...")); - assertThat(highlight("//this is not a javadoc", tokenizer), is("//this is not a javadoc")); + assertThat(highlight("/**this is a javadoc*/ public ...", tokenizer)).isEqualTo("/**this is a javadoc*/ public ..."); + assertThat(highlight("//this is not a javadoc", tokenizer)).isEqualTo("//this is not a javadoc"); } @Test public void testHighlightingOnMultipleLines() { - assertThat(highlight("/**this is \n a javadoc*/ private", tokenizer), is("/**this is \n a javadoc*/ private")); + assertThat(highlight("/**this is \n a javadoc*/ private", tokenizer)).isEqualTo("/**this is \n a javadoc*/ private"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/KeywordsTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/KeywordsTokenizerTest.java index 086196a6c4a..e36736db923 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/KeywordsTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/KeywordsTokenizerTest.java @@ -19,9 +19,7 @@ */ package org.sonar.colorizer; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; import org.junit.Test; @@ -31,28 +29,28 @@ public class KeywordsTokenizerTest { @Test public void testColorizeKeywords() { KeywordsTokenizer tokenizer = new KeywordsTokenizer("", "", "public", "new"); - assertThat(highlight("new()", tokenizer), is("new()")); - assertThat(highlight("public new get()", tokenizer), is("public new get()")); - assertThat(highlight("publication", tokenizer), is("publication")); + assertThat(highlight("new()", tokenizer)).isEqualTo("new()"); + assertThat(highlight("public new get()", tokenizer)).isEqualTo("public new get()"); + assertThat(highlight("publication", tokenizer)).isEqualTo("publication"); } @Test public void testUnderscoreAndDigit() { KeywordsTokenizer tokenizer = new KeywordsTokenizer("", "", "_01public"); - assertThat(highlight("_01public", tokenizer), is("_01public")); + assertThat(highlight("_01public", tokenizer)).isEqualTo("_01public"); } @Test public void testCaseSensitive() { KeywordsTokenizer tokenizer = new KeywordsTokenizer("", "", "public"); - assertThat(highlight("PUBLIC Public public", tokenizer), is("PUBLIC Public public")); + assertThat(highlight("PUBLIC Public public", tokenizer)).isEqualTo("PUBLIC Public public"); } @Test public void testClone() { KeywordsTokenizer tokenizer = new KeywordsTokenizer("", "", "public", "[a-z]+"); KeywordsTokenizer cloneTokenizer = tokenizer.clone(); - assertThat(tokenizer, is(not(cloneTokenizer))); - assertThat(highlight("public 1234", cloneTokenizer), is("public 1234")); + assertThat(tokenizer).isNotEqualTo(cloneTokenizer); + assertThat(highlight("public 1234", cloneTokenizer)).isEqualTo("public 1234"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/RegexpTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/RegexpTokenizerTest.java index c1d0ba47a5a..86475b2587d 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/RegexpTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/RegexpTokenizerTest.java @@ -19,29 +19,28 @@ */ package org.sonar.colorizer; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; -import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; - import org.junit.Test; +import static org.fest.assertions.Assertions.assertThat; +import static org.sonar.colorizer.SyntaxHighlighterTestingHarness.highlight; + public class RegexpTokenizerTest { - RegexpTokenizer tokenHighlighter;; + RegexpTokenizer tokenHighlighter; + ; @Test public void testHighlight() { tokenHighlighter = new RegexpTokenizer("", "", "[0-9]+"); - assertThat(highlight("123, word = 435;", tokenHighlighter), is("123, word = 435;")); + assertThat(highlight("123, word = 435;", tokenHighlighter)).isEqualTo("123, word = 435;"); } - + @Test public void testClone() { RegexpTokenizer tokenizer = new RegexpTokenizer("", "", "[a-z]+"); RegexpTokenizer cloneTokenizer = tokenizer.clone(); - assertThat(tokenizer, is(not(cloneTokenizer))); - assertThat(highlight("public 1234", cloneTokenizer), is("public 1234")); + assertThat(tokenizer).isNotEqualTo(cloneTokenizer); + assertThat(highlight("public 1234", cloneTokenizer)).isEqualTo("public 1234"); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/TokenizerDispatcherTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/TokenizerDispatcherTest.java index e933ea36443..07548806439 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/TokenizerDispatcherTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/TokenizerDispatcherTest.java @@ -19,41 +19,40 @@ */ package org.sonar.colorizer; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - import org.junit.Test; import org.sonar.channel.Channel; import org.sonar.channel.CodeReader; +import java.util.Arrays; + +import static org.fest.assertions.Assertions.assertThat; + public class TokenizerDispatcherTest { @Test public void testPipeCodeTokenizer() { TokenizerDispatcher colorization = newColorizer(); - assertThat(colorization.colorize("public void get(){"), is("public void get(){")); + assertThat(colorization.colorize("public void get(){")).isEqualTo("public void get(){"); } @Test public void testKeywordsCodeTokenizer() { TokenizerDispatcher colorization = newColorizer(new KeywordsTokenizer("", "", JavaKeywords.get())); - assertThat(colorization.colorize("public void get(){"), is("public void get(){")); + assertThat(colorization.colorize("public void get(){")).isEqualTo("public void get(){"); } @Test public void testPriorityToComment() { TokenizerDispatcher colorization = newColorizer(new CDocTokenizer("", ""), new KeywordsTokenizer("", "", JavaKeywords - .get())); - assertThat(colorization.colorize("assert //public void get(){"), is("assert //public void get(){")); + .get())); + assertThat(colorization.colorize("assert //public void get(){")).isEqualTo("assert //public void get(){"); } @Test public void testCommentThenStringThenJavaKeywords() { TokenizerDispatcher colorization = newColorizer(new CDocTokenizer("", ""), new LiteralTokenizer("", ""), - new KeywordsTokenizer("", "", JavaKeywords.get())); - assertThat(colorization.colorize("assert(\"message\"); //comment"), is("assert(\"message\"); //comment")); + new KeywordsTokenizer("", "", JavaKeywords.get())); + assertThat(colorization.colorize("assert(\"message\"); //comment")).isEqualTo("assert(\"message\"); //comment"); } @Test(expected = IllegalStateException.class) diff --git a/sonar-deprecated/pom.xml b/sonar-deprecated/pom.xml index 6d00457ee5a..09672a84961 100644 --- a/sonar-deprecated/pom.xml +++ b/sonar-deprecated/pom.xml @@ -38,12 +38,6 @@ test
- - ${project.groupId} - sonar-testing-harness - ${project.version} - test - org.mockito mockito-all diff --git a/sonar-deprecated/src/test/java/org/sonar/api/resources/MethodTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/MethodTest.java index 8d8c7b66f80..b4155c39a72 100644 --- a/sonar-deprecated/src/test/java/org/sonar/api/resources/MethodTest.java +++ b/sonar-deprecated/src/test/java/org/sonar/api/resources/MethodTest.java @@ -21,7 +21,7 @@ package org.sonar.api.resources; import org.junit.Test; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; public class MethodTest { diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java index a58e3d4bdc1..643f673f89c 100644 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java +++ b/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java @@ -26,8 +26,7 @@ import org.sonar.api.CoreProperties; import java.util.Map; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -41,11 +40,11 @@ public class RuleUtilsTest { final Map map = RuleUtils.getPriorityWeights(conf); - assertThat(map.get(RulePriority.BLOCKER), is(10)); - assertThat(map.get(RulePriority.CRITICAL), is(5)); - assertThat(map.get(RulePriority.MAJOR), is(2)); - assertThat(map.get(RulePriority.MINOR), is(1)); - assertThat(map.get(RulePriority.INFO), is(0)); + assertThat(map.get(RulePriority.BLOCKER)).isEqualTo(10); + assertThat(map.get(RulePriority.CRITICAL)).isEqualTo(5); + assertThat(map.get(RulePriority.MAJOR)).isEqualTo(2); + assertThat(map.get(RulePriority.MINOR)).isEqualTo(1); + assertThat(map.get(RulePriority.INFO)).isEqualTo(0); } @Test @@ -55,11 +54,11 @@ public class RuleUtilsTest { final Map map = RuleUtils.getPriorityWeights(conf); - assertThat(map.get(RulePriority.BLOCKER), is(1)); - assertThat(map.get(RulePriority.CRITICAL), is(5)); - assertThat(map.get(RulePriority.MAJOR), is(1)); - assertThat(map.get(RulePriority.MINOR), is(1)); - assertThat(map.get(RulePriority.INFO), is(1)); + assertThat(map.get(RulePriority.BLOCKER)).isEqualTo(1); + assertThat(map.get(RulePriority.CRITICAL)).isEqualTo(5); + assertThat(map.get(RulePriority.MAJOR)).isEqualTo(1); + assertThat(map.get(RulePriority.MINOR)).isEqualTo(1); + assertThat(map.get(RulePriority.INFO)).isEqualTo(1); } } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java index 6262929bbb2..146106b3442 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java @@ -23,17 +23,16 @@ import com.google.common.base.Predicate; import org.junit.Test; import org.sonar.duplications.index.CloneGroup; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; public class DuplicationPredicatesTest { @Test public void testNumberOfUnitsNotLessThan() { Predicate predicate = DuplicationPredicates.numberOfUnitsNotLessThan(5); - assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(6).build()), is(true)); - assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(5).build()), is(true)); - assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(4).build()), is(false)); + assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(6).build())).isTrue(); + assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(5).build())).isTrue(); + assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(4).build())).isFalse(); } } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java index 5b6481b5ef4..93d8068b088 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java @@ -26,7 +26,7 @@ import org.sonar.duplications.statement.Statement; import java.util.Collections; import java.util.List; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat; /** diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java index 6a26def7e81..b44ded89664 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java @@ -30,12 +30,18 @@ import org.sonar.duplications.index.ClonePart; import org.sonar.duplications.index.MemoryCloneIndex; import org.sonar.duplications.junit.TestNamePrinter; -import java.util.*; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; -import static org.hamcrest.Matchers.*; +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.*; +import static org.junit.matchers.JUnitMatchers.hasItem; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup; public abstract class DetectorTestCase { @@ -51,11 +57,11 @@ public abstract class DetectorTestCase { */ protected static Block newBlock(String resourceId, ByteArray hash, int index) { return Block.builder() - .setResourceId(resourceId) - .setBlockHash(hash) - .setIndexInFile(index) - .setLines(index, index + LINES_PER_BLOCK) - .build(); + .setResourceId(resourceId) + .setBlockHash(hash) + .setIndexInFile(index) + .setLines(index, index + LINES_PER_BLOCK) + .build(); } protected static ClonePart newClonePart(String resourceId, int unitStart, int cloneUnitLength) { @@ -80,8 +86,8 @@ public abstract class DetectorTestCase { @Test public void exampleFromPaper() { CloneIndex index = createIndex( - newBlocks("y", "2 3 4 5"), - newBlocks("z", "3 4")); + newBlocks("y", "2 3 4 5"), + newBlocks("z", "3 4")); Block[] fileBlocks = newBlocks("x", "1 2 3 4 5 6"); List result = detect(index, fileBlocks); @@ -89,13 +95,13 @@ public abstract class DetectorTestCase { assertEquals(2, result.size()); assertThat(result, hasCloneGroup(4, - newClonePart("x", 1, 4), - newClonePart("y", 0, 4))); + newClonePart("x", 1, 4), + newClonePart("y", 0, 4))); assertThat(result, hasCloneGroup(2, - newClonePart("x", 2, 2), - newClonePart("y", 1, 2), - newClonePart("z", 0, 2))); + newClonePart("x", 2, 2), + newClonePart("y", 1, 2), + newClonePart("z", 0, 2))); } /** @@ -114,8 +120,8 @@ public abstract class DetectorTestCase { @Test public void exampleFromPaperWithModifiedResourceIds() { CloneIndex cloneIndex = createIndex( - newBlocks("a", "2 3 4 5"), - newBlocks("b", "3 4")); + newBlocks("a", "2 3 4 5"), + newBlocks("b", "3 4")); Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6"); List clones = detect(cloneIndex, fileBlocks); @@ -123,13 +129,13 @@ public abstract class DetectorTestCase { assertThat(clones.size(), is(2)); assertThat(clones, hasCloneGroup(4, - newClonePart("c", 1, 4), - newClonePart("a", 0, 4))); + newClonePart("c", 1, 4), + newClonePart("a", 0, 4))); assertThat(clones, hasCloneGroup(2, - newClonePart("c", 2, 2), - newClonePart("a", 1, 2), - newClonePart("b", 0, 2))); + newClonePart("c", 2, 2), + newClonePart("a", 1, 2), + newClonePart("b", 0, 2))); } /** @@ -149,8 +155,8 @@ public abstract class DetectorTestCase { @Test public void example1() { CloneIndex index = createIndex( - newBlocks("b", "3 4 5 6"), - newBlocks("c", "5 6 7")); + newBlocks("b", "3 4 5 6"), + newBlocks("c", "5 6 7")); Block[] fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9"); List result = detect(index, fileBlocks); @@ -158,17 +164,17 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(3)); assertThat(result, hasCloneGroup(4, - newClonePart("a", 2, 4), - newClonePart("b", 0, 4))); + newClonePart("a", 2, 4), + newClonePart("b", 0, 4))); assertThat(result, hasCloneGroup(3, - newClonePart("a", 4, 3), - newClonePart("c", 0, 3))); + newClonePart("a", 4, 3), + newClonePart("c", 0, 3))); assertThat(result, hasCloneGroup(2, - newClonePart("a", 4, 2), - newClonePart("b", 2, 2), - newClonePart("c", 0, 2))); + newClonePart("a", 4, 2), + newClonePart("b", 2, 2), + newClonePart("c", 0, 2))); } /** @@ -186,8 +192,8 @@ public abstract class DetectorTestCase { @Test public void example2() { CloneIndex index = createIndex( - newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"), - newBlocks("c", "1 2 3 4")); + newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"), + newBlocks("c", "1 2 3 4")); Block[] fileBlocks = newBlocks("a", "1 2 3 5"); List result = detect(index, fileBlocks); @@ -195,11 +201,11 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(1)); assertThat(result, hasCloneGroup(3, - newClonePart("a", 0, 3), - newClonePart("b", 0, 3), - newClonePart("b", 4, 3), - newClonePart("b", 8, 3), - newClonePart("c", 0, 3))); + newClonePart("a", 0, 3), + newClonePart("b", 0, 3), + newClonePart("b", 4, 3), + newClonePart("b", 8, 3), + newClonePart("c", 0, 3))); } /** @@ -223,8 +229,8 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(1)); assertThat(result, hasCloneGroup(2, - newClonePart("a", 0, 2), - newClonePart("a", 3, 2))); + newClonePart("a", 0, 2), + newClonePart("a", 3, 2))); } /** @@ -243,7 +249,7 @@ public abstract class DetectorTestCase { @Test public void covered() { CloneIndex index = createIndex( - newBlocks("b", "1 2 1 2")); + newBlocks("b", "1 2 1 2")); Block[] fileBlocks = newBlocks("a", "1 2 1"); List result = detect(index, fileBlocks); @@ -251,13 +257,13 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(2)); assertThat(result, hasCloneGroup(3, - newClonePart("a", 0, 3), - newClonePart("b", 0, 3))); + newClonePart("a", 0, 3), + newClonePart("b", 0, 3))); assertThat(result, hasCloneGroup(2, - newClonePart("a", 0, 2), - newClonePart("b", 0, 2), - newClonePart("b", 2, 2))); + newClonePart("a", 0, 2), + newClonePart("b", 0, 2), + newClonePart("b", 2, 2))); } /** @@ -275,7 +281,7 @@ public abstract class DetectorTestCase { @Test public void problemWithNestedCloneGroups() { CloneIndex index = createIndex( - newBlocks("b", "1 2 1 2 1 2 1")); + newBlocks("b", "1 2 1 2 1 2 1")); Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2"); List result = detect(index, fileBlocks); @@ -283,13 +289,13 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(2)); assertThat(result, hasCloneGroup(6, - newClonePart("a", 0, 6), - newClonePart("b", 0, 6))); + newClonePart("a", 0, 6), + newClonePart("b", 0, 6))); assertThat(result, hasCloneGroup(5, - newClonePart("a", 0, 5), - newClonePart("b", 0, 5), - newClonePart("b", 2, 5))); + newClonePart("a", 0, 5), + newClonePart("b", 0, 5), + newClonePart("b", 2, 5))); } /** @@ -307,8 +313,8 @@ public abstract class DetectorTestCase { @Test public void fileAlreadyInIndex() { CloneIndex index = createIndex( - newBlocks("a", "1 2 3"), - newBlocks("b", "1 2 4")); + newBlocks("a", "1 2 3"), + newBlocks("b", "1 2 4")); // Note about blocks with hashes "3", "4" and "5": those blocks here in order to not face another problem - with EOF (see separate test) Block[] fileBlocks = newBlocks("a", "1 2 5"); List result = detect(index, fileBlocks); @@ -317,8 +323,8 @@ public abstract class DetectorTestCase { assertThat(result.size(), is(1)); assertThat(result, hasCloneGroup(2, - newClonePart("a", 0, 2), - newClonePart("b", 0, 2))); + newClonePart("a", 0, 2), + newClonePart("b", 0, 2))); } /** @@ -360,17 +366,17 @@ public abstract class DetectorTestCase { @Test public void problemWithEndOfFile() { CloneIndex cloneIndex = createIndex( - newBlocks("b", "1 2 3 4")); + newBlocks("b", "1 2 3 4")); Block[] fileBlocks = - newBlocks("a", "1 2 3"); + newBlocks("a", "1 2 3"); List clones = detect(cloneIndex, fileBlocks); print(clones); assertThat(clones.size(), is(1)); assertThat(clones, hasCloneGroup(3, - newClonePart("a", 0, 3), - newClonePart("b", 0, 3))); + newClonePart("a", 0, 3), + newClonePart("b", 0, 3))); } /** @@ -391,9 +397,9 @@ public abstract class DetectorTestCase { public void same_lines_but_different_indexes() { CloneIndex cloneIndex = createIndex(); Block.Builder block = Block.builder() - .setResourceId("a") - .setLines(0, 1); - Block[] fileBlocks = new Block[] { + .setResourceId("a") + .setLines(0, 1); + Block[] fileBlocks = new Block[]{ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(), block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(), block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build() diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java index 4b63abc419e..9831f4531cb 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java @@ -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 { diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java index ea16c856685..8c11dc4ebae 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import java.io.IOException; import java.util.List; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; public class TokenizerBridgeTest { diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java index 66fa6dc8294..96818f66752 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java @@ -35,7 +35,7 @@ import org.sonar.duplications.token.TokenChunker; import java.util.Collection; import java.util.List; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; /** diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java index bd0e07d598c..5995290c307 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java @@ -34,9 +34,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.List; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertThat; +import static org.fest.assertions.Assertions.assertThat; public class JavaStatementBuilderTest { @@ -49,12 +47,12 @@ public class JavaStatementBuilderTest { @Test public void shouldIgnoreImportStatement() { - assertThat(chunk("import org.sonar.duplications.java;").size(), is(0)); + assertThat(chunk("import org.sonar.duplications.java;")).isEmpty(); } @Test public void shouldIgnorePackageStatement() { - assertThat(chunk("package org.sonar.duplications.java;").size(), is(0)); + assertThat(chunk("package org.sonar.duplications.java;")).isEmpty(); } @Test @@ -63,66 +61,66 @@ public class JavaStatementBuilderTest { "@Entity" + "@Table(name = \"properties\")" + "@Column(updatable = true, nullable = true)"); - assertThat(statements.size(), is(3)); - assertThat(statements.get(0).getValue(), is("@Entity")); - assertThat(statements.get(1).getValue(), is("@Table(name=$CHARS)")); - assertThat(statements.get(2).getValue(), is("@Column(updatable=true,nullable=true)")); + assertThat(statements).hasSize(3); + assertThat(statements.get(0).getValue()).isEqualTo("@Entity"); + assertThat(statements.get(1).getValue()).isEqualTo("@Table(name=$CHARS)"); + assertThat(statements.get(2).getValue()).isEqualTo("@Column(updatable=true,nullable=true)"); } @Test public void shouldHandleIf() { List statements = chunk("if (a > b) { something(); }"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("if(a>b)")); - assertThat(statements.get(1).getValue(), is("something()")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); statements = chunk("if (a > b) { something(); } else { somethingOther(); }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("if(a>b)")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("else")); - assertThat(statements.get(3).getValue(), is("somethingOther()")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("else"); + assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()"); statements = chunk("if (a > 0) { something(); } else if (a == 0) { somethingOther(); }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("if(a>$NUMBER)")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("elseif(a==$NUMBER)")); - assertThat(statements.get(3).getValue(), is("somethingOther()")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("if(a>$NUMBER)"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("elseif(a==$NUMBER)"); + assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()"); } @Test public void shouldHandleFor() { List statements = chunk("for (int i = 0; i < 10; i++) { something(); }"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("for(inti=$NUMBER;i<$NUMBER;i++)")); - assertThat(statements.get(1).getValue(), is("something()")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("for(inti=$NUMBER;i<$NUMBER;i++)"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); statements = chunk("for (Item item : items) { something(); }"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("for(Itemitem:items)")); - assertThat(statements.get(1).getValue(), is("something()")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("for(Itemitem:items)"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); } @Test public void shouldHandleWhile() { List statements = chunk("while (i < args.length) { something(); }"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("while(i statements = chunk("do { something(); } while (true);"); - assertThat(statements.size(), is(3)); - assertThat(statements.get(0).getValue(), is("do")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("while(true)")); + assertThat(statements.size()).isEqualTo(3); + assertThat(statements.get(0).getValue()).isEqualTo("do"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("while(true)"); } @Test @@ -133,13 +131,13 @@ public class JavaStatementBuilderTest { " case 2 : monthString=\"February\"; break;" + " default: monthString=\"Invalid\";" + "}"); - assertThat(statements.size(), is(6)); - assertThat(statements.get(0).getValue(), is("switch(month)")); - assertThat(statements.get(1).getValue(), is("case$NUMBER:monthString=$CHARS")); - assertThat(statements.get(2).getValue(), is("break")); - assertThat(statements.get(3).getValue(), is("case$NUMBER:monthString=$CHARS")); - assertThat(statements.get(4).getValue(), is("break")); - assertThat(statements.get(5).getValue(), is("default:monthString=$CHARS")); + assertThat(statements.size()).isEqualTo(6); + assertThat(statements.get(0).getValue()).isEqualTo("switch(month)"); + assertThat(statements.get(1).getValue()).isEqualTo("case$NUMBER:monthString=$CHARS"); + assertThat(statements.get(2).getValue()).isEqualTo("break"); + assertThat(statements.get(3).getValue()).isEqualTo("case$NUMBER:monthString=$CHARS"); + assertThat(statements.get(4).getValue()).isEqualTo("break"); + assertThat(statements.get(5).getValue()).isEqualTo("default:monthString=$CHARS"); } /** @@ -152,20 +150,20 @@ public class JavaStatementBuilderTest { " case 'a': case 'b': case 'c': something(); break;" + " case 'd': case 'e': case 'f': somethingOther(); break;" + "}"); - assertThat(statements.size(), is(5)); - assertThat(statements.get(0).getValue(), is("switch(a)")); - assertThat(statements.get(1).getValue(), is("case$CHARS:case$CHARS:case$CHARS:something()")); - assertThat(statements.get(2).getValue(), is("break")); - assertThat(statements.get(3).getValue(), is("case$CHARS:case$CHARS:case$CHARS:somethingOther()")); - assertThat(statements.get(4).getValue(), is("break")); + assertThat(statements.size()).isEqualTo(5); + assertThat(statements.get(0).getValue()).isEqualTo("switch(a)"); + assertThat(statements.get(1).getValue()).isEqualTo("case$CHARS:case$CHARS:case$CHARS:something()"); + assertThat(statements.get(2).getValue()).isEqualTo("break"); + assertThat(statements.get(3).getValue()).isEqualTo("case$CHARS:case$CHARS:case$CHARS:somethingOther()"); + assertThat(statements.get(4).getValue()).isEqualTo("break"); } @Test public void shouldHandleArray() { List statements = chunk("new Integer[] { 1, 2, 3, 4 };"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("newInteger[]")); - assertThat(statements.get(1).getValue(), is("{$NUMBER,$NUMBER,$NUMBER,$NUMBER}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("newInteger[]"); + assertThat(statements.get(1).getValue()).isEqualTo("{$NUMBER,$NUMBER,$NUMBER,$NUMBER}"); } /** @@ -174,95 +172,95 @@ public class JavaStatementBuilderTest { @Test public void shouldHandleMultidimensionalArray() { List statements = chunk("new Integer[][] { { 1, 2 }, {3, 4} };"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("newInteger[][]")); - assertThat(statements.get(1).getValue(), is("{{$NUMBER,$NUMBER},{$NUMBER,$NUMBER}}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]"); + assertThat(statements.get(1).getValue()).isEqualTo("{{$NUMBER,$NUMBER},{$NUMBER,$NUMBER}}"); statements = chunk("new Integer[][] { null, {3, 4} };"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("newInteger[][]")); - assertThat(statements.get(1).getValue(), is("{null,{$NUMBER,$NUMBER}}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]"); + assertThat(statements.get(1).getValue()).isEqualTo("{null,{$NUMBER,$NUMBER}}"); } @Test public void shouldHandleTryCatch() { List statements; statements = chunk("try { } catch (Exception e) { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("{}")); - assertThat(statements.get(2).getValue(), is("catch(Exceptione)")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } catch (Exception e) { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exceptione)")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } catch (Exception e) { onException(); }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exceptione)")); - assertThat(statements.get(3).getValue(), is("onException()")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); + assertThat(statements.get(3).getValue()).isEqualTo("onException()"); statements = chunk("try { something(); } catch (Exception1 e) { onException1(); } catch (Exception2 e) { onException2(); }"); - assertThat(statements.size(), is(6)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exception1e)")); - assertThat(statements.get(3).getValue(), is("onException1()")); - assertThat(statements.get(4).getValue(), is("catch(Exception2e)")); - assertThat(statements.get(5).getValue(), is("onException2()")); + assertThat(statements.size()).isEqualTo(6); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1e)"); + assertThat(statements.get(3).getValue()).isEqualTo("onException1()"); + assertThat(statements.get(4).getValue()).isEqualTo("catch(Exception2e)"); + assertThat(statements.get(5).getValue()).isEqualTo("onException2()"); } @Test public void shouldHandleTryFinnaly() { List statements; statements = chunk("try { } finally { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("{}")); - assertThat(statements.get(2).getValue(), is("finally")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); + assertThat(statements.get(2).getValue()).isEqualTo("finally"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } finally { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("finally")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("finally"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } finally { somethingOther(); }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("finally")); - assertThat(statements.get(3).getValue(), is("somethingOther()")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("finally"); + assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()"); } @Test public void shouldHandleTryCatchFinally() { List statements; statements = chunk("try { } catch (Exception e) {} finally { }"); - assertThat(statements.size(), is(6)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("{}")); - assertThat(statements.get(2).getValue(), is("catch(Exceptione)")); - assertThat(statements.get(3).getValue(), is("{}")); - assertThat(statements.get(4).getValue(), is("finally")); - assertThat(statements.get(5).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(6); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); + assertThat(statements.get(4).getValue()).isEqualTo("finally"); + assertThat(statements.get(5).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } catch (Exception e) { onException(); } finally { somethingOther(); }"); - assertThat(statements.size(), is(6)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exceptione)")); - assertThat(statements.get(3).getValue(), is("onException()")); - assertThat(statements.get(4).getValue(), is("finally")); - assertThat(statements.get(5).getValue(), is("somethingOther()")); + assertThat(statements.size()).isEqualTo(6); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); + assertThat(statements.get(3).getValue()).isEqualTo("onException()"); + assertThat(statements.get(4).getValue()).isEqualTo("finally"); + assertThat(statements.get(5).getValue()).isEqualTo("somethingOther()"); } /** @@ -272,25 +270,25 @@ public class JavaStatementBuilderTest { public void shouldHandleMultiCatch() { List statements; statements = chunk("try { } catch (Exception1 | Exception2 e) { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("{}")); - assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)")); - assertThat(statements.get(3).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); + assertThat(statements.get(3).getValue()).isEqualTo("{}"); statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { onException(); }"); - assertThat(statements.size(), is(4)); - assertThat(statements.get(0).getValue(), is("try")); - assertThat(statements.get(1).getValue(), is("something()")); - assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)")); - assertThat(statements.get(3).getValue(), is("onException()")); + assertThat(statements.size()).isEqualTo(4); + assertThat(statements.get(0).getValue()).isEqualTo("try"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); + assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); + assertThat(statements.get(3).getValue()).isEqualTo("onException()"); } /** @@ -300,30 +298,30 @@ public class JavaStatementBuilderTest { public void shouldHandleTryWithResource() { List statements; statements = chunk("try (FileInputStream in = new FileInputStream()) {}"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream())")); - assertThat(statements.get(1).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream()) {}"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream())")); - assertThat(statements.get(1).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream())"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream();) {}"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream();)")); - assertThat(statements.get(1).getValue(), is("{}")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream();)"); + assertThat(statements.get(1).getValue()).isEqualTo("{}"); statements = chunk("try (FileInputStream in = new FileInputStream()) { something(); }"); - assertThat(statements.size(), is(2)); - assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream())")); - assertThat(statements.get(1).getValue(), is("something()")); + assertThat(statements.size()).isEqualTo(2); + assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())"); + assertThat(statements.get(1).getValue()).isEqualTo("something()"); } @Test public void realExamples() { - assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size(), greaterThan(0)); - assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size(), greaterThan(0)); + assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size()).isGreaterThan(0); + assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size()).isGreaterThan(0); } private List chunk(File file) { diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java index 33bf33a0f0a..93ff6fc6c34 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java @@ -37,8 +37,8 @@ import java.io.Reader; import java.util.Arrays; import java.util.List; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; -import static org.hamcrest.number.OrderingComparisons.greaterThan; import static org.junit.Assert.assertThat; public class JavaTokenProducerTest { diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java index c3f6e6450b8..12d89238fc0 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java @@ -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.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java index 6cbeaeb0145..fa845303942 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java @@ -19,14 +19,13 @@ */ package org.sonar.duplications.token; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyZeroInteractions; - import org.junit.Test; import org.sonar.channel.CodeReader; +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyZeroInteractions; + public class BlackHoleTokenChannelTest { @Test @@ -35,9 +34,9 @@ public class BlackHoleTokenChannelTest { TokenQueue output = mock(TokenQueue.class); CodeReader codeReader = new CodeReader("ABCD"); - assertThat(channel.consume(codeReader, output), is(true)); - assertThat(codeReader.getLinePosition(), is(1)); - assertThat(codeReader.getColumnPosition(), is(3)); + assertThat(channel.consume(codeReader, output)).isTrue(); + assertThat(codeReader.getLinePosition()).isEqualTo(1); + assertThat(codeReader.getColumnPosition()).isEqualTo(3); verifyZeroInteractions(output); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java index 6fda53df331..55bcb1bfff0 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java @@ -19,40 +19,37 @@ */ package org.sonar.api.database.model; -import org.hamcrest.core.Is; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.StringContains.containsString; +import static org.fest.assertions.Assertions.assertThat; public class UserTest { @Test public void testToString() { User user = new User() - .setEmail("super@m.an") - .setLogin("superman") - .setName("Superman"); - assertThat(user.toString(), containsString("super@m.an")); - assertThat(user.toString(), containsString("superman")); - assertThat(user.toString(), containsString("Superman")); + .setEmail("super@m.an") + .setLogin("superman") + .setName("Superman"); + assertThat(user.toString()).contains("super@m.an"); + assertThat(user.toString()).contains("superman"); + assertThat(user.toString()).contains("Superman"); } @Test public void testEquals() { User one = new User() - .setLogin("one") - .setName("One"); + .setLogin("one") + .setName("One"); User two = new User() - .setLogin("two") - .setName("Two"); + .setLogin("two") + .setName("Two"); - assertThat(one.equals(one), Is.is(true)); - assertThat(one.equals(new User().setLogin("one")), Is.is(true)); - assertThat(one.equals(two), Is.is(false)); + assertThat(one.equals(one)).isTrue(); + assertThat(one.equals(new User().setLogin("one"))).isTrue(); + assertThat(one.equals(two)).isFalse(); - assertEquals(one.hashCode(), new User().setLogin("one").hashCode()); + assertThat(one.hashCode()).isEqualTo(new User().setLogin("one").hashCode()); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java index 7f0000faea7..2a891daa089 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java @@ -34,23 +34,20 @@ import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.IsCollectionContaining.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; +import static org.fest.assertions.Assertions.assertThat; public class ManifestUtilsTest { @Rule public TemporaryFolder tempDir = new TemporaryFolder(); - @Test + @Test public void emptyManifest() throws Exception { Manifest mf = new Manifest(); File jar = createJar(mf, "emptyManifest.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar})); - assertThat(ManifestUtils.getPropertyValues(classloader, "foo").size(), is(0)); + assertThat(ManifestUtils.getPropertyValues(classloader, "foo")).isEmpty(); } @Test @@ -62,8 +59,7 @@ public class ManifestUtilsTest { URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar})); List values = ManifestUtils.getPropertyValues(classloader, "foo"); - assertThat(values.size(), is(1)); - assertThat(values, hasItem("bar")); + assertThat(values).containsOnly("bar"); } @Test @@ -78,8 +74,7 @@ public class ManifestUtilsTest { URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar1, jar2})); List values = ManifestUtils.getPropertyValues(classloader, "foo"); - assertThat(values.size(), is(2)); - assertThat(values, hasItems("bar", "otherbar")); + assertThat(values).containsOnly("bar", "otherbar"); } private File createJar(Manifest mf, String name) throws Exception { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java index 86ccebc95bb..a69e4ab7edf 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java @@ -22,21 +22,21 @@ package org.sonar.api.utils; import org.junit.Test; import org.slf4j.Logger; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.internal.matchers.IsCollectionContaining.hasItem; -import static org.junit.internal.matchers.StringContains.containsString; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class ValidationMessagesTest { @Test public void emptyMessages() { ValidationMessages messages = ValidationMessages.create(); - assertThat(messages.hasErrors(), is(false)); - assertThat(messages.hasWarnings(), is(false)); - assertThat(messages.hasInfos(), is(false)); + assertThat(messages.hasErrors()).isFalse(); + assertThat(messages.hasWarnings()).isFalse(); + assertThat(messages.hasInfos()).isFalse(); Logger logger = mock(Logger.class); messages.log(logger); @@ -49,13 +49,13 @@ public class ValidationMessagesTest { public void addError() { ValidationMessages messages = ValidationMessages.create(); messages.addErrorText("my error"); - assertThat(messages.hasErrors(), is(true)); - assertThat(messages.hasWarnings(), is(false)); - assertThat(messages.hasInfos(), is(false)); - assertThat(messages.getErrors().size(), is(1)); - assertThat(messages.getErrors(), hasItem("my error")); - assertThat(messages.toString(), containsString("my error")); - + assertThat(messages.hasErrors()).isTrue(); + assertThat(messages.hasWarnings()).isFalse(); + assertThat(messages.hasInfos()).isFalse(); + assertThat(messages.getErrors()).hasSize(1); + assertThat(messages.getErrors()).contains("my error"); + assertThat(messages.toString()).contains("my error"); + Logger logger = mock(Logger.class); messages.log(logger); verify(logger, times(1)).error("my error"); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java index 518bc8a9f0e..b3891832993 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java @@ -49,7 +49,7 @@ public class CommandExecutorTest { private File workDir; @Before - public void setUp() { + public void before() throws IOException { workDir = tempFolder.newFolder(testName.getMethodName()); } diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 4a57f7c8bfa..9b798cee8d8 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -165,6 +165,16 @@ test-jar test + + junit + junit + test + + + org.easytesting + fest-assert + test + org.mockito mockito-all @@ -256,6 +266,24 @@ + + copy-generated-webapp + + process-resources + + copy-resources + + + ${project.build.directory}/${project.build.finalName} + true + + + src/main/webapp/build + false + + + +
@@ -295,29 +323,6 @@ - - maven-resources-plugin - - - copy-generated-webapp - - process-resources - - copy-resources - - - ${project.build.directory}/${project.build.finalName} - true - - - src/main/webapp/build - false - - - - - - org.apache.maven.plugins maven-war-plugin @@ -397,6 +402,7 @@ + org.apache.maven.plugins maven-resources-plugin diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerSetupQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerSetupQueryTest.java index 94a18f4ff44..e7f899a06c7 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerSetupQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerSetupQueryTest.java @@ -19,16 +19,15 @@ */ package org.sonar.wsclient.services; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - import org.junit.Test; +import static org.fest.assertions.Assertions.assertThat; + public class ServerSetupQueryTest extends QueryTestCase { @Test public void index() { ServerSetupQuery query = new ServerSetupQuery(); - assertThat(query.getUrl(), is("/api/server/setup")); - assertThat(query.getModelClass().getName(), is(ServerSetup.class.getName())); + assertThat(query.getUrl()).isEqualTo("/api/server/setup"); + assertThat(query.getModelClass().getName()).isEqualTo(ServerSetup.class.getName()); } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java index 551a0597fd8..4fac008d1a0 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java @@ -24,9 +24,9 @@ import org.sonar.wsclient.services.Resource; import java.util.List; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertThat; public class ResourceUnmarshallerTest extends UnmarshallerTestCase { -- 2.39.5