Various code improvements from IntelliJ inspections

This commit is contained in:
Graham Triggs 2017-09-18 00:21:04 +01:00
parent 0ae8d005e4
commit 4859eb7da1
267 changed files with 879 additions and 1400 deletions

View file

@ -198,7 +198,7 @@ public abstract class AbstractTestClass {
file.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
message.append(" contains file '" + pathname + "'\n");
message.append(" contains file '").append(pathname).append("'\n");
return true;
}
});
@ -421,16 +421,10 @@ public abstract class AbstractTestClass {
StringReader reader = new StringReader(docString);
Document doc = builder.parse(new InputSource(reader));
xformer.transform(new DOMSource(doc), new StreamResult(result));
} catch (ParserConfigurationException e) {
fail(e.toString());
} catch (SAXException e) {
fail(e.toString());
} catch (IOException e) {
fail(e.toString());
} catch (TransformerException e) {
} catch (ParserConfigurationException | TransformerException | IOException | SAXException e) {
fail(e.toString());
}
return result.toString().replaceAll(">\\s+<", "><");
return result.toString().replaceAll(">\\s+<", "><");
}
protected <T extends Comparable<T>> void assertEqualSets(String label,

View file

@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -245,9 +246,7 @@ public class HasPermissionFactoryTest extends AbstractTestClass {
private <T> List<T> list(T... elements) {
List<T> l = new ArrayList<T>();
for (T element : elements) {
l.add(element);
}
Collections.addAll(l, elements);
return l;
}

View file

@ -6,8 +6,6 @@ import static org.junit.Assert.*;
import java.io.StringReader;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

View file

@ -189,14 +189,11 @@ public class ProgramLoginTest extends AbstractTestClass {
try {
servlet.doGet(request, response);
} catch (ServletException e) {
log.error(e, e);
fail(e.toString());
} catch (IOException e) {
} catch (ServletException | IOException e) {
log.error(e, e);
fail(e.toString());
}
}
}
private void assert403() {
assertEquals("status", 403, response.getStatus());

View file

@ -9,7 +9,6 @@ import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Level;
import org.junit.BeforeClass;
import org.junit.Test;

View file

@ -16,6 +16,8 @@ import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
import java.util.Collections;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
@ -132,9 +134,7 @@ public class ListClassGroupsControllerTest extends ListControllerTestBase {
private VClassGroup vClassGroup(String uri, String name, int rank,
VClass... vClasses) {
VClassGroup group = new VClassGroup(uri, name, rank);
for (VClass vClass : vClasses) {
group.add(vClass);
}
Collections.addAll(group, vClasses);
return group;
}

View file

@ -11,7 +11,6 @@ import java.io.IOException;
import javax.servlet.ServletException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.log4j.Level;
@ -214,8 +213,6 @@ public class JsonServletTest extends AbstractTestClass {
JsonNode result = mapper.readTree(resp.getOutput());
assertEquals("errorMessage", expected, getFieldValue(result, "errorMessage").asText());
assertEquals("status", SC_INTERNAL_SERVER_ERROR, resp.getStatus());
} catch (JsonProcessingException e) {
fail(e.toString());
} catch (IOException e) {
fail(e.toString());
}
@ -233,8 +230,6 @@ public class JsonServletTest extends AbstractTestClass {
assertEquals("vclass uri", vclassId, getFieldValue(vclassObj, "URI").asText());
assertEquals("status", SC_OK, resp.getStatus());
} catch (JsonProcessingException e) {
fail(e.toString());
} catch (IOException e) {
fail(e.toString());
}

View file

@ -785,11 +785,7 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
@Override
public Boolean fn(ObjectPropertyStatement ops) {
if (PROPERTY_OBJECT_VISIBLE.equals(ops.getPropertyURI())) {
if (isFauxHidden(ops)) {
return false;
} else {
return true;
}
return !isFauxHidden(ops);
}
if (PROPERTY_OBJECT_MAYBE.equals(ops.getPropertyURI())
&& URI_INDIVIDUAL_SPECIAL.equals(ops.getSubjectURI())) {

View file

@ -3,23 +3,14 @@
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import net.sf.jga.algorithms.Summarize;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.BaseFiltering;
public class VitroFiltersFactoryTest {

View file

@ -3,9 +3,7 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import org.apache.log4j.Level;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.apache.jena.ontology.DatatypeProperty;
@ -13,7 +11,6 @@ import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;

View file

@ -2,16 +2,13 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import org.apache.log4j.Level;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler;
import org.apache.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;

View file

@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.io.StringReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert;

View file

@ -3,8 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;

View file

@ -208,11 +208,11 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
StmtIterator stmts = ontModel.listStatements(
ontModel.getResource(URI_USER1), null, (RDFNode) null);
if (stmts.hasNext()) {
String message = "Expecting no statements to remain in the model, but found:\n";
StringBuilder message = new StringBuilder("Expecting no statements to remain in the model, but found:\n");
while (stmts.hasNext()) {
message += " " + formatStatement(stmts.next()) + "\n";
message.append(" ").append(formatStatement(stmts.next())).append("\n");
}
fail(message);
fail(message.toString());
}
}

View file

@ -320,27 +320,27 @@ public class VClassJenaTest {
}
return labelStr;
} else if (isBooleanClassExpression(cls)) {
String labelStr = "(";
StringBuilder labelStr = new StringBuilder("(");
if (cls.isComplementClass()) {
labelStr += "not ";
labelStr.append("not ");
ComplementClass ccls = (ComplementClass) cls.as(ComplementClass.class);
labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList,wadf);
labelStr.append(getLabelForClass(ccls.getOperand(), withPrefix, forPickList, wadf));
} else if (cls.isIntersectionClass()) {
IntersectionClass icls = (IntersectionClass) cls.as(IntersectionClass.class);
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) {
OntClass operand = (OntClass) operandIt.next();
labelStr += getLabelForClass(operand,withPrefix,forPickList,wadf);
labelStr.append(getLabelForClass(operand, withPrefix, forPickList, wadf));
if (operandIt.hasNext()) {
labelStr += " and ";
labelStr.append(" and ");
}
}
} else if (cls.isUnionClass()) {
UnionClass icls = (UnionClass) cls.as(UnionClass.class);
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) {
OntClass operand = (OntClass) operandIt.next();
labelStr += getLabelForClass(operand,withPrefix,forPickList,wadf);
labelStr.append(getLabelForClass(operand, withPrefix, forPickList, wadf));
if (operandIt.hasNext()) {
labelStr += " or ";
labelStr.append(" or ");
}
}
}

View file

@ -3,7 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.edit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.apache.jena.rdf.model.Literal;

View file

@ -4,23 +4,12 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
public class RdfLiteralHashTest {

View file

@ -5,8 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.filters;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletResponse;
import org.junit.Assert;
import org.junit.Test;

View file

@ -6,7 +6,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.HashSet;

View file

@ -599,9 +599,9 @@ public class VitroModelFactoryTest extends AbstractTestClass {
private void dumpMethodCalls(String message, Object proxy) {
System.out.println(message + " method calls:");
for (MethodCall call : ((MethodCallRecorder) proxy).getMethodCalls()) {
String formatted = " " + call.getName();
StringBuilder formatted = new StringBuilder(" " + call.getName());
for (Object arg : call.getArgList()) {
formatted += " " + arg.getClass();
formatted.append(" ").append(arg.getClass());
}
System.out.println(formatted);
}

View file

@ -16,7 +16,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.junit.Before;
import org.junit.Test;

View file

@ -2,21 +2,13 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.io.StringReader;
import org.junit.Assert;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
public class UpdateKnowledgeBaseTest extends AbstractTestClass {
@org.junit.Test
public void testMigrateDisplayModel14() {
return;
}
}
}

View file

@ -22,11 +22,6 @@ import java.util.Set;
import org.junit.Ignore;
import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.ServletContextStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
import stubs.javax.servlet.http.HttpSessionStub;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Statement;

View file

@ -109,9 +109,7 @@ public class StringResultsMappingTest extends AbstractTestClass {
@SafeVarargs
private static <T> List<T> list(T... items) {
List<T> l = new ArrayList<>();
for (T item : items) {
l.add(item);
}
Collections.addAll(l, items);
return l;
}

View file

@ -1063,9 +1063,7 @@ public class DumpDirectiveTest {
}
public void setFavoriteColors(String...colors) {
for (String color : colors) {
favoriteColors.add(color);
}
Collections.addAll(favoriteColors, colors);
}
// void setDegrees(Map<String, String> degrees) {

View file

@ -19,7 +19,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
/**

View file

@ -210,10 +210,10 @@ public class HttpServletRequestStub implements HttpServletRequest {
return null;
}
String qs = "";
StringBuilder qs = new StringBuilder();
for (String key : parameters.keySet()) {
for (String value : parameters.get(key)) {
qs += "&" + key + "=" + URLEncoder.encode(value);
qs.append("&").append(key).append("=").append(URLEncoder.encode(value));
}
}
return "?" + qs.substring(1);

View file

@ -4,7 +4,6 @@ package stubs.javax.servlet.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;