forked from fmueller/sonar-scala
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing unit tests for some surefire classes
- Loading branch information
Showing
4 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/test/java/org/sonar/plugins/scala/surefire/UnitTestIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Sonar Scala Plugin | ||
* Copyright (C) 2011 - 2014 All contributors | ||
* [email protected] | ||
* | ||
* 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 02 | ||
*/ | ||
package org.sonar.plugins.scala.surefire; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertSame; | ||
|
||
public class UnitTestIndexTest { | ||
|
||
@Test | ||
public void shouldIndexNewClassname() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
|
||
UnitTestClassReport report = index.index("org.sonar.Foo"); | ||
|
||
assertThat(report.getTests(), is(0L)); | ||
assertThat(index.size(), is(1)); | ||
assertSame(index.get("org.sonar.Foo"), report); | ||
} | ||
|
||
@Test | ||
public void shouldNotReIndex() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
|
||
UnitTestClassReport report1 = index.index("org.sonar.Foo"); | ||
UnitTestClassReport report2 = index.index("org.sonar.Foo"); | ||
|
||
assertSame(report1, report2); | ||
assertThat(report1.getTests(), is(0L)); | ||
assertThat(index.size(), is(1)); | ||
assertSame(index.get("org.sonar.Foo"), report1); | ||
} | ||
|
||
@Test | ||
public void shouldRemoveClassname() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
|
||
index.index("org.sonar.Foo"); | ||
index.remove("org.sonar.Foo"); | ||
|
||
assertThat(index.size(), is(0)); | ||
assertThat(index.get("org.sonar.Foo"), nullValue()); | ||
} | ||
|
||
@Test | ||
public void shouldMergeClasses() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
UnitTestClassReport innerClass = index.index("org.sonar.Foo$Bar"); | ||
innerClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_ERROR).setDurationMilliseconds(500L)); | ||
innerClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_OK).setDurationMilliseconds(200L)); | ||
UnitTestClassReport publicClass = index.index("org.sonar.Foo"); | ||
publicClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_ERROR).setDurationMilliseconds(1000L)); | ||
publicClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_FAILURE).setDurationMilliseconds(350L)); | ||
|
||
index.merge("org.sonar.Foo$Bar", "org.sonar.Foo"); | ||
|
||
assertThat(index.size(), is(1)); | ||
UnitTestClassReport report = index.get("org.sonar.Foo"); | ||
assertThat(report.getTests(), is(4L)); | ||
assertThat(report.getFailures(), is(1L)); | ||
assertThat(report.getErrors(), is(2L)); | ||
assertThat(report.getSkipped(), is(0L)); | ||
assertThat(report.getResults().size(), is(4)); | ||
assertThat(report.getDurationMilliseconds(), is(500L + 200L + 1000L + 350L)); | ||
} | ||
|
||
@Test | ||
public void shouldRenameClassWhenMergingToNewClass() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
UnitTestClassReport innerClass = index.index("org.sonar.Foo$Bar"); | ||
innerClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_ERROR).setDurationMilliseconds(500L)); | ||
innerClass.add(new UnitTestResult().setStatus(UnitTestResult.STATUS_OK).setDurationMilliseconds(200L)); | ||
|
||
index.merge("org.sonar.Foo$Bar", "org.sonar.Foo"); | ||
|
||
assertThat(index.size(), is(1)); | ||
UnitTestClassReport report = index.get("org.sonar.Foo"); | ||
assertThat(report.getTests(), is(2L)); | ||
assertThat(report.getFailures(), is(0L)); | ||
assertThat(report.getErrors(), is(1L)); | ||
assertThat(report.getSkipped(), is(0L)); | ||
assertThat(report.getResults().size(), is(2)); | ||
assertThat(report.getDurationMilliseconds(), is(500L + 200L)); | ||
} | ||
|
||
@Test | ||
public void shouldNotFailWhenMergingUnknownClass() { | ||
UnitTestIndex index = new UnitTestIndex(); | ||
|
||
index.merge("org.sonar.Foo$Bar", "org.sonar.Foo"); | ||
|
||
assertThat(index.size(), is(0)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/org/sonar/plugins/scala/surefire/UnitTestResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Sonar Scala Plugin | ||
* Copyright (C) 2011 - 2014 All contributors | ||
* [email protected] | ||
* | ||
* 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 02 | ||
*/ | ||
package org.sonar.plugins.scala.surefire; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class UnitTestResultTest { | ||
|
||
@Test | ||
public void shouldBeError() { | ||
UnitTestResult result = new UnitTestResult().setStatus(UnitTestResult.STATUS_ERROR); | ||
assertThat(result.getStatus(), is(UnitTestResult.STATUS_ERROR)); | ||
assertThat(result.isError(), is(true)); | ||
assertThat(result.isErrorOrFailure(), is(true)); | ||
} | ||
|
||
@Test | ||
public void shouldBeFailure() { | ||
UnitTestResult result = new UnitTestResult().setStatus(UnitTestResult.STATUS_FAILURE); | ||
assertThat(result.getStatus(), is(UnitTestResult.STATUS_FAILURE)); | ||
assertThat(result.isError(), is(false)); | ||
assertThat(result.isErrorOrFailure(), is(true)); | ||
} | ||
|
||
@Test | ||
public void shouldBeSuccess() { | ||
UnitTestResult result = new UnitTestResult().setStatus(UnitTestResult.STATUS_OK); | ||
assertThat(result.getStatus(), is(UnitTestResult.STATUS_OK)); | ||
assertThat(result.isError(), is(false)); | ||
assertThat(result.isErrorOrFailure(), is(false)); | ||
} | ||
} |