Browse Source

SONAR-2501 remove org.sonar.api.tests

tags/3.5
Simon Brandhof 11 years ago
parent
commit
b53e3b99f8

+ 0
- 2
sonar-batch/src/main/java/org/sonar/batch/bootstrap/InspectionModule.java View File

@@ -26,7 +26,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.tests.ProjectTestsImpl;
import org.sonar.batch.DefaultProfileLoader;
import org.sonar.batch.DefaultProjectClasspath;
import org.sonar.batch.DefaultProjectFileSystem2;
@@ -102,7 +101,6 @@ public class InspectionModule extends Module {
container.addSingleton(DefaultModelFinder.class);
container.addSingleton(DefaultProfileLoader.class);
container.addSingleton(DryRunExporter.class);
container.addSingleton(ProjectTestsImpl.class);
container.addPicoAdapter(new ProfileProvider());
}


+ 0
- 83
sonar-plugin-api/src/main/java/org/sonar/api/tests/FileTest.java View File

@@ -1,83 +0,0 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/

package org.sonar.api.tests;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

public class FileTest {

private String key;

private List<Test> tests;

public FileTest(String key) {
this.key = key;
tests = newArrayList();
}

public String getKey() {
return key;
}

public List<Test> getTests() {
return tests;
}

public void addTest(Test test) {
tests.add(test);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

FileTest fileTest = (FileTest) o;

if (!key.equals(fileTest.key)) {
return false;
}

return true;
}

@Override
public int hashCode() {
return key.hashCode();
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("key", key)
.append("tests", tests)
.toString();
}
}

+ 0
- 35
sonar-plugin-api/src/main/java/org/sonar/api/tests/ProjectTests.java View File

@@ -1,35 +0,0 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/

package org.sonar.api.tests;

import java.util.Collection;

/**
*
* @since 3.5
*/
public interface ProjectTests {

void addTest(String fileTestKey, Test test);

void cover(String fileTestKey, String test, String mainFile, Collection<Integer> lines);

}

+ 0
- 86
sonar-plugin-api/src/main/java/org/sonar/api/tests/ProjectTestsImpl.java View File

@@ -1,86 +0,0 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/

package org.sonar.api.tests;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;

import java.util.Collection;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

public class ProjectTestsImpl implements ProjectTests, BatchExtension {

private static final Logger LOG = LoggerFactory.getLogger(ProjectTestsImpl.class);
private List<FileTest> fileTests;

public ProjectTestsImpl() {
fileTests = newArrayList();
}

public void addTest(String fileTestKey, Test test) {
FileTest fileTest = getFileTest(fileTestKey);
fileTest.addTest(test);

LOG.info("Added a new test : " + toString());
}

public void cover(String fileTestKey, String test, String mainFile, Collection<Integer> lines) {
FileTest fileTest = find(fileTestKey);
if (fileTest != null) {
LOG.info("Covering - File test : " + fileTestKey + ", test : " + test + ", file : " + mainFile + ", lines : " + Iterables.toString(lines));
}
}

public List<FileTest> getFileTests() {
return fileTests;
}

private FileTest getFileTest(final String key) {
FileTest fileTest = find(key);
if (fileTest == null) {
fileTest = new FileTest(key);
fileTests.add(fileTest);
}
return fileTest;
}

private FileTest find(final String key) {
return Iterables.find(fileTests, new Predicate<FileTest>() {
public boolean apply(FileTest fileTest) {
return fileTest.getKey().equals(key);
}
}, null);
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("fileTests", fileTests)
.toString();
}
}

+ 0
- 107
sonar-plugin-api/src/main/java/org/sonar/api/tests/Test.java View File

@@ -1,107 +0,0 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/

package org.sonar.api.tests;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class Test {

private String name;
private String stackTrace;
private String message;
private long durationMilliseconds;
private String status;

public Test(String name) {
this.name = name;
}

public long getDurationMilliseconds() {
return durationMilliseconds;
}

public Test setDurationMilliseconds(long durationMilliseconds) {
this.durationMilliseconds = durationMilliseconds;
return this;
}

public String getStatus() {
return status;
}

public Test setStatus(String status) {
this.status = status;
return this;
}

public String getStackTrace() {
return stackTrace;
}

public Test setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
return this;
}

public String getMessage() {
return message;
}

public Test setMessage(String message) {
this.message = message;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Test test = (Test) o;

if (!name.equals(test.name)) {
return false;
}

return true;
}

@Override
public int hashCode() {
return name.hashCode();
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("name", name)
.append("durationMilliseconds", durationMilliseconds)
.append("status", status)
.append("message", message)
.append("stackTrace", stackTrace)
.toString();
}
}

+ 0
- 72
sonar-plugin-api/src/test/java/org/sonar/api/tests/ProjectTestsImplTest.java View File

@@ -1,72 +0,0 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/

package org.sonar.api.tests;

import org.junit.Before;
import org.junit.Test;

import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;

public class ProjectTestsImplTest {

private ProjectTestsImpl projectTests;

@Before
public void before(){
projectTests = new ProjectTestsImpl();
}

@Test
public void should_add_new_test() throws Exception {
org.sonar.api.tests.Test test = new org.sonar.api.tests.Test("test")
.setStatus("ok")
.setMessage("message")
.setStackTrace("stacktrace")
.setDurationMilliseconds(10)
;
projectTests.addTest("key", test);
assertThat(projectTests.getFileTests()).hasSize(1);
assertThat(projectTests.getFileTests().get(0)).isEqualTo(new FileTest("key"));
assertThat(projectTests.getFileTests().get(0).getTests()).hasSize(1);
assertThat(projectTests.getFileTests().get(0).getTests().get(0)).isEqualTo(test);
}

@Test
public void should_add_new_test_on_existing_file_test() throws Exception {
org.sonar.api.tests.Test test = new org.sonar.api.tests.Test("test").setStatus("ok");
projectTests.addTest("key", test);

org.sonar.api.tests.Test test2 = new org.sonar.api.tests.Test("test2").setStatus("ok");
projectTests.addTest("key", test2);

assertThat(projectTests.getFileTests()).hasSize(1);
assertThat(projectTests.getFileTests().get(0).getTests()).hasSize(2);
}

@Test
public void should_add_coverage_info() throws Exception {
org.sonar.api.tests.Test test = new org.sonar.api.tests.Test("test").setStatus("ok");
projectTests.addTest("key", test);

projectTests.cover("key", "test", "mainFile", newArrayList(1, 2));
}
}

Loading…
Cancel
Save