*/
package org.sonar.java.bytecode.loader;
+import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
+
+import java.io.File;
+import java.net.URL;
+
import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import java.io.File;
-import java.net.URL;
-
-import org.junit.Test;
-import org.sonar.java.ast.SquidTestUtils;
-
public class FileSystemLoaderTest {
@Test(expected = IllegalArgumentException.class)
URL url = loader.findResource("tags/TagName.class");
assertThat(url, notNullValue());
- assertThat(url.toString(), allOf(startsWith("file:"), endsWith("TagName.class")));
+ assertThat(url.toString(), startsWith("file:"));
+ assertThat(url.toString(), endsWith("TagName.class"));
loader.close();
URL url = loader.findResource("META-INF/MANIFEST.MF");
assertThat(url, notNullValue());
- assertThat(url.toString(), allOf(startsWith("jar:"), endsWith("hello.jar!/META-INF/MANIFEST.MF")));
+ assertThat(url.toString(), startsWith("jar:"));
+ assertThat(url.toString(), endsWith("hello.jar!/META-INF/MANIFEST.MF"));
InputStream is = url.openStream();
try {
public void shouldReturnUserAgent() {
Bootstrapper bootstrapper = new Bootstrapper("test/0.1", "http://unknown.foo", new File("target"));
String userAgent = bootstrapper.getUserAgent();
+
assertThat(userAgent.length(), greaterThan(0));
- assertThat(userAgent, allOf(startsWith("sonar-bootstrapper/"), endsWith(" test/0.1")));
+ assertThat(userAgent, startsWith("sonar-bootstrapper/"));
+ assertThat(userAgent, endsWith(" test/0.1"));
}
@Test
public class TokenizerDispatcher {
- private Channel[] tokenizers;
+ private Channel<HtmlCodeBuilder>[] tokenizers;
public TokenizerDispatcher(Channel<HtmlCodeBuilder>... tokenizers) {
this.tokenizers = tokenizers;
private DaoUtils() {
}
+ @SuppressWarnings("unchecked")
public static List<Class<?>> getDaoClasses() {
return ImmutableList.of(
ActiveDashboardDao.class,
}
- protected List evaluateAnnotatedClasses(Object extension, Class annotation) {
+ protected List evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) {
List<Object> results = Lists.newArrayList();
Class aClass = extension.getClass();
while (aClass != null) {
import org.apache.commons.lang.ClassUtils;
+import java.lang.annotation.Annotation;
import java.util.List;
/**
/**
* Searches for a class annotation. All inheritance tree is analysed.
*/
- public static <A> A getClassAnnotation(final Object object, final Class<A> annotationClass) {
- Class initialClass = (object instanceof Class ? (Class) object : object.getClass());
+ public static <A extends Annotation> A getClassAnnotation(Object object, Class<A> annotationClass) {
+ Class<?> initialClass = (object instanceof Class<?> ? (Class<?>) object : object.getClass());
A result = null;
- Class aClass=initialClass;
+ Class<?> aClass = initialClass;
while (aClass != null && result == null) {
- result = (A)aClass.getAnnotation(annotationClass);
+ result = aClass.getAnnotation(annotationClass);
aClass = aClass.getSuperclass();
}
- if (result==null) {
- List<Class> interfaces = ClassUtils.getAllInterfaces(initialClass);
- for (Class anInterface : interfaces) {
- result = (A)anInterface.getAnnotation(annotationClass);
- if (result!=null) {
+ if (result == null) {
+ List<Class<?>> interfaces = ClassUtils.getAllInterfaces(initialClass);
+ for (Class<?> anInterface : interfaces) {
+ result = anInterface.getAnnotation(annotationClass);
+ if (result != null) {
break;
}
}
*/
package org.sonar.api.utils.dag;
+import com.google.common.collect.Lists;
+
import org.sonar.api.utils.SonarException;
import java.util.*;
public List sort() {
sortNodes();
- List result = new ArrayList();
+ List<Object> result = Lists.newArrayList();
for (Node node : nodes) {
result.add(node.getObject());
}
public class AbstractnessFormulaTest {
AbstractnessFormula abstractness = new AbstractnessFormula();
- Measurable<Metric> measurable = new SourcePackage("pac1");
+ SourcePackage measurable = new SourcePackage("pac1");
@Test
public void testCalculate() {
public class CommentLinesDensityFormulaTest {
CommentLinesDensityFormula formula = new CommentLinesDensityFormula();
- Measurable<Metric> measurable = new SourceClass("com.Toto");
+ SourceClass measurable = new SourceClass("com.Toto");
@Test
public void calculateDensityOnEmptyFile() {
public class CommentLinesWithoutHeaderFormulaTest {
CommentLinesWithoutHeaderFormula formula = new CommentLinesWithoutHeaderFormula();
- Measurable<Metric> measurable = new SourceClass("com.Toto");
+ SourceClass measurable = new SourceClass("com.Toto");
@Test
public void calculateDensityOnEmptyFile() {
public class DistanceFormulaTest {
DistanceFormula distance = new DistanceFormula();
- Measurable<Metric> measurable = new SourcePackage("pac1");
+ SourcePackage measurable = new SourcePackage("pac1");
@Test
public void calculateBestDistance() {
public class InstabilityFormulaTest {
InstabilityFormula distance = new InstabilityFormula();
- Measurable<Metric> measurable = new SourcePackage("pac1");
+ SourcePackage measurable = new SourcePackage("pac1");
@Test
public void calculateBestStability() {
public class PublicDocumentedApiDensityFormulaTest {
PublicDocumentedApiDensityFormula formula = new PublicDocumentedApiDensityFormula();
- Measurable<Metric> measurable = new SourceClass("com.Toto");
+ SourceClass measurable = new SourceClass("com.Toto");
@Test
public void calculateWhenNoPublicApi() {