Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QA] Automatic code analysis from Jetbrains IntelliJ-IDEA #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -115,17 +109,15 @@ static Output path(String path) {

List<String> orderedTables =
Arrays.asList(
new String[] {
"GS_CATEGORY",
"GS_RESOURCE",
"GS_ATTRIBUTE",
"GS_USER",
"GS_USER_ATTRIBUTE",
"GS_USERGROUP",
"GS_USERGROUP_MEMBERS",
"GS_SECURITY",
"GS_STORED_DATA"
});
"GS_CATEGORY",
"GS_RESOURCE",
"GS_ATTRIBUTE",
"GS_USER",
"GS_USER_ATTRIBUTE",
"GS_USERGROUP",
"GS_USERGROUP_MEMBERS",
"GS_SECURITY",
"GS_STORED_DATA");

Pattern searchInserts =
Pattern.compile(
Expand Down Expand Up @@ -210,7 +202,8 @@ List<String> filterInserts(String script) {
if (insertsByTable.containsKey(tableName)) {
insertsByTable.get(tableName).add(insert);
} else {
insertsByTable.put(tableName, new ArrayList<String>(Arrays.asList(insert)));
insertsByTable.put(
tableName, new ArrayList<String>(Collections.singletonList(insert)));
}
}
return flat(insertsByTable);
Expand All @@ -226,7 +219,7 @@ Optional<String> exportH2AsScript() throws IOException {
try {
Script.execute(
"jdbc:h2:" + h2path.get() + ";ACCESS_MODE_DATA=r", username, password, os);
String script = new String(os.toByteArray(), StandardCharsets.UTF_8);
String script = os.toString(StandardCharsets.UTF_8);
return Optional.of(script);
} catch (SQLException e) {
System.err.println("Error extracting data from the H2 database: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
*/
package it.geosolutions.geostore.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import it.geosolutions.geostore.cli.H2ToPgSQLExporter.Output;
import it.geosolutions.geostore.cli.H2ToPgSQLExporter.OutputType;
Expand All @@ -44,7 +43,7 @@ public void existingFolder() throws IOException {

Output output = exporter.validateOutputFile();

assertTrue(output.type == OutputType.FILE);
assertSame(output.type, OutputType.FILE);
assertEquals(exporter.outputPath, output.path.get());
}

Expand All @@ -54,7 +53,7 @@ public void pathWithoutExtension() throws IOException {

Output output = exporter.validateOutputFile();

assertTrue(output.type == OutputType.FILE);
assertSame(output.type, OutputType.FILE);
assertTrue(output.path.get().toLowerCase().endsWith(".sql"));
}

Expand All @@ -64,7 +63,7 @@ public void notExistingFolder() throws IOException {

Output output = exporter.validateOutputFile();

assertTrue(output.type == OutputType.INVALID);
assertSame(output.type, OutputType.INVALID);
}

@Test
Expand All @@ -73,7 +72,7 @@ public void standardOutput() throws IOException {

Output output = exporter.validateOutputFile();

assertTrue(output.type == OutputType.STDOUT);
assertSame(output.type, OutputType.STDOUT);
}

private String getValidPath() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public class Attribute implements Serializable {
@PrePersist
public void onPreUpdate() throws Exception {
if (textValue == null && numberValue == null && dateValue == null) {
throw new NullPointerException(
"Null value not allowed in attribute: " + this.toString());
throw new NullPointerException("Null value not allowed in attribute: " + this);

} else if (this.textValue == null && this.numberValue != null ^ this.dateValue != null
|| this.numberValue == null && this.dateValue == null) {
Expand All @@ -122,8 +121,7 @@ public void onPreUpdate() throws Exception {

} else {
throw new Exception(
"Only one DataType can be not-null inside the Attribute entity: "
+ this.toString());
"Only one DataType can be not-null inside the Attribute entity: " + this);
}
}

Expand Down Expand Up @@ -192,7 +190,7 @@ public String getValue() {
case NUMBER:
return numberValue.toString();
case STRING:
return textValue.toString();
return textValue;
default:
throw new IllegalStateException("Unknown type " + type);
}
Expand Down Expand Up @@ -347,7 +345,6 @@ public boolean equals(Object obj) {
if (textValue == null) {
if (other.textValue != null) return false;
} else if (!textValue.equals(other.textValue)) return false;
if (type != other.type) return false;
return true;
return type == other.type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,14 @@ public boolean equals(Object obj) {
return false;
}
if (resource == null) {
if (other.resource != null) {
return false;
}
} else if (!resource.equals(other.resource)) {
return false;
}
return other.resource == null;
} else return resource.equals(other.resource);
// if ( security == null ) {
// if ( other.security != null ) {
// return false;
// }
// } else if ( !security.equals(other.security) ) {
// return false;
// }

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,7 @@ public boolean equals(Object obj) {
}
if (editor == null) {
return other.editor == null;
} else if (!editor.equals(other.editor)) {
return false;
}

return true;
} else return editor.equals(other.editor);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,7 @@ public boolean equals(Object obj) {
return false;
}
if (user == null) {
if (other.user != null) {
return false;
}
} else if (!user.equals(other.user)) {
return false;
}

return true;
return other.user == null;
} else return user.equals(other.user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ public boolean equals(Object obj) {
return false;
}
if (resource == null) {
if (other.resource != null) {
return false;
}
} else if (!resource.equals(other.resource)) {
return false;
}

return true;
return other.resource == null;
} else return resource.equals(other.resource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class User implements Serializable {
@Enumerated(EnumType.STRING)
private Role role;

public User() {};
public User() {}

public User(User user) {
this.id = user.id;
Expand Down Expand Up @@ -294,7 +294,7 @@ public String toString() {

if (groups != null) {
builder.append(", ");
builder.append("group=").append(groups.toString());
builder.append("group=").append(groups);
}

if (role != null) {
Expand Down Expand Up @@ -380,13 +380,7 @@ public boolean equals(Object obj) {
return false;
}
if (security == null) {
if (other.security != null) {
return false;
}
} else if (!security.equals(other.security)) {
return false;
}

return true;
return other.security == null;
} else return security.equals(other.security);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,7 @@ public boolean equals(Object obj) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}

return true;
return other.value == null;
} else return value.equals(other.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,7 @@ public boolean equals(Object obj) {
}

if (attributes == null) {
if (other.attributes != null) {
return false;
}
} else if (!attributes.equals(other.attributes)) {
return false;
}

return true;
return other.attributes == null;
} else return attributes.equals(other.attributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,7 @@ public boolean equals(Object obj) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}

return true;
return other.value == null;
} else return value.equals(other.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
public enum DataType {
STRING,
NUMBER,
DATE;
DATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public String groupName() {
* @return
*/
public static boolean isAllowedName(String groupNameToCheck) {
if (EVERYONE.groupName().equalsIgnoreCase(groupNameToCheck)) {
return false;
}
return true;
return !EVERYONE.groupName().equalsIgnoreCase(groupNameToCheck);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public String userName() {
* @return
*/
public static boolean isAllowedName(String groupNameToCheck) {
if (GUEST.userName().equalsIgnoreCase(groupNameToCheck)) {
return false;
}
return true;
return !GUEST.userName().equalsIgnoreCase(groupNameToCheck);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void doTheTest(Attribute a0) {
System.out.println(a1);
System.out.println(s);

assertTrue(a0.equals(a1));
assertEquals(a0, a1);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package it.geosolutions.geostore.core.model;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

Expand All @@ -34,7 +34,7 @@ public CategoryTest() {}
public void testMarshallingString() throws Exception {
Category c0 = new Category();
c0.setName("testatt");
c0.setId(1l);
c0.setId(1L);

doTheTest(c0);
}
Expand All @@ -47,6 +47,6 @@ private void doTheTest(Category a0) {
System.out.println(a1);
System.out.println(s);

assertTrue(a0.equals(a1));
assertEquals(a0, a1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package it.geosolutions.geostore.core.model;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

Expand All @@ -45,6 +45,6 @@ private void doTheTest(SecurityRule a0) {
String s = MARSHALER.marshal(a0);
SecurityRule a1 = MARSHALER.unmarshal(s);

assertTrue(a0.equals(a1));
assertEquals(a0, a1);
}
}
Loading
Loading