Closes #2459: Fix Code Smells
This commit is contained in:
parent
aa697dc2ed
commit
25abb49276
|
@ -13,7 +13,6 @@ import java.time.ZonedDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.apache.ibatis.jdbc.RuntimeSqlException;
|
import org.apache.ibatis.jdbc.RuntimeSqlException;
|
||||||
|
@ -78,9 +77,7 @@ public class SampleDataGenerator {
|
||||||
private List<String> parseScripts(Stream<String> scripts) {
|
private List<String> parseScripts(Stream<String> scripts) {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
DB db = DB.getDB(connection);
|
DB db = DB.getDB(connection);
|
||||||
return scripts
|
return scripts.map(script -> SqlReplacer.getScriptAsSql(db, now, script)).toList();
|
||||||
.map(script -> SqlReplacer.getScriptAsSql(db, now, script))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeSqlException("Connection to database failed.", e);
|
throw new RuntimeSqlException("Connection to database failed.", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.security.auth.Subject;
|
import javax.security.auth.Subject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -61,7 +60,7 @@ public class CurrentUserContextImpl implements CurrentUserContext {
|
||||||
.map(Principal::getName)
|
.map(Principal::getName)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.map(this::convertAccessId)
|
.map(this::convertAccessId)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
LOGGER.trace("No groupIds found in subject!");
|
LOGGER.trace("No groupIds found in subject!");
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
|
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
|
||||||
} else if (factoryResult instanceof Stream) {
|
} else if (factoryResult instanceof Stream) {
|
||||||
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
|
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
|
||||||
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
|
newChildrenForDynamicContainer = nodes.toList();
|
||||||
} else if (factoryResult instanceof Iterable) {
|
} else if (factoryResult instanceof Iterable) {
|
||||||
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
|
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
|
||||||
} else if (factoryResult instanceof Iterator) {
|
} else if (factoryResult instanceof Iterator) {
|
||||||
|
@ -142,8 +142,11 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
Store store = getMethodLevelStore(extensionContext);
|
Store store = getMethodLevelStore(extensionContext);
|
||||||
return (T)
|
return (T)
|
||||||
Stream.of(annotation.value())
|
Stream.of(annotation.value())
|
||||||
.peek(a -> store.put(ACCESS_IDS_STORE_KEY, a))
|
.map(
|
||||||
.map(wrapTestsInDynamicContainer);
|
a -> {
|
||||||
|
store.put(ACCESS_IDS_STORE_KEY, a);
|
||||||
|
return wrapTestsInDynamicContainer.apply(a);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
|
return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
|
||||||
|
@ -207,8 +210,11 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
AnnotationSupport.findRepeatableAnnotations(context.getElement(), WithAccessId.class);
|
AnnotationSupport.findRepeatableAnnotations(context.getElement(), WithAccessId.class);
|
||||||
Store store = getMethodLevelStore(context);
|
Store store = getMethodLevelStore(context);
|
||||||
return accessIds.stream()
|
return accessIds.stream()
|
||||||
.peek(a -> store.put(ACCESS_IDS_STORE_KEY, a))
|
.map(
|
||||||
.map(JaasExtensionInvocationContext::new);
|
a -> {
|
||||||
|
store.put(ACCESS_IDS_STORE_KEY, a);
|
||||||
|
return new JaasExtensionInvocationContext(a);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
@ -259,7 +265,7 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
Stream.of(withAccessId.user()).map(UserPrincipal::new),
|
Stream.of(withAccessId.user()).map(UserPrincipal::new),
|
||||||
Arrays.stream(withAccessId.groups()).map(GroupPrincipal::new))
|
Arrays.stream(withAccessId.groups()).map(GroupPrincipal::new))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import pro.taskana.common.api.exceptions.SystemException;
|
import pro.taskana.common.api.exceptions.SystemException;
|
||||||
import pro.taskana.common.internal.util.ReflectionUtil;
|
import pro.taskana.common.internal.util.ReflectionUtil;
|
||||||
|
|
||||||
|
@ -43,6 +42,6 @@ public class SimpleParser<T> implements PropertyParser<T> {
|
||||||
return Arrays.stream(str.split(Pattern.quote(separator)))
|
return Arrays.stream(str.split(Pattern.quote(separator)))
|
||||||
.filter(not(String::isEmpty))
|
.filter(not(String::isEmpty))
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,8 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items);
|
return (o instanceof ComparableVersion comparableVersion)
|
||||||
|
&& items.equals(comparableVersion.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,8 +42,8 @@ public class ReflectionUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getRawClass(Type type) {
|
public static Class<?> getRawClass(Type type) {
|
||||||
if (type instanceof ParameterizedType) {
|
if (type instanceof ParameterizedType parameterizedType) {
|
||||||
return getRawClass(((ParameterizedType) type).getRawType());
|
return getRawClass(parameterizedType.getRawType());
|
||||||
}
|
}
|
||||||
return (Class<?>) type;
|
return (Class<?>) type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,8 +504,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isH2OrPostgresIntegrityConstraintViolation(PersistenceException e) {
|
private boolean isH2OrPostgresIntegrityConstraintViolation(PersistenceException e) {
|
||||||
return e.getCause() instanceof SQLException
|
return e.getCause() instanceof SQLException sqlException
|
||||||
&& ((SQLException) e.getCause()).getSQLState().equals("23503");
|
&& sqlException.getSQLState().equals("23503");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -107,8 +107,8 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
|
|
||||||
Iterable<DynamicNode> newChildrenForDynamicContainer;
|
Iterable<DynamicNode> newChildrenForDynamicContainer;
|
||||||
// TestFactory must have one of the following return types. See link above for further details
|
// TestFactory must have one of the following return types. See link above for further details
|
||||||
if (factoryResult instanceof DynamicNode) {
|
if (factoryResult instanceof DynamicNode dynamicNode) {
|
||||||
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
|
newChildrenForDynamicContainer = Collections.singleton(dynamicNode);
|
||||||
} else if (factoryResult instanceof Stream) {
|
} else if (factoryResult instanceof Stream) {
|
||||||
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
|
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
|
||||||
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
|
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
|
||||||
|
@ -116,8 +116,8 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
|
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
|
||||||
} else if (factoryResult instanceof Iterator) {
|
} else if (factoryResult instanceof Iterator) {
|
||||||
newChildrenForDynamicContainer = () -> (Iterator<DynamicNode>) factoryResult;
|
newChildrenForDynamicContainer = () -> (Iterator<DynamicNode>) factoryResult;
|
||||||
} else if (factoryResult instanceof DynamicNode[]) {
|
} else if (factoryResult instanceof DynamicNode[] dynamicNodes) {
|
||||||
newChildrenForDynamicContainer = Arrays.asList((DynamicNode[]) factoryResult);
|
newChildrenForDynamicContainer = Arrays.asList(dynamicNodes);
|
||||||
} else {
|
} else {
|
||||||
throw new SystemException(
|
throw new SystemException(
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -217,8 +217,7 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
Iterable<DynamicNode> nodes, Map<String, List<DynamicNode>> childrenMap) {
|
Iterable<DynamicNode> nodes, Map<String, List<DynamicNode>> childrenMap) {
|
||||||
nodes.forEach(
|
nodes.forEach(
|
||||||
node -> {
|
node -> {
|
||||||
if (node instanceof DynamicContainer) {
|
if (node instanceof DynamicContainer container) {
|
||||||
DynamicContainer container = (DynamicContainer) node;
|
|
||||||
List<DynamicNode> children = container.getChildren().collect(Collectors.toList());
|
List<DynamicNode> children = container.getChildren().collect(Collectors.toList());
|
||||||
childrenMap.put(container.hashCode() + container.getDisplayName(), children);
|
childrenMap.put(container.hashCode() + container.getDisplayName(), children);
|
||||||
persistDynamicContainerChildren(children, childrenMap);
|
persistDynamicContainerChildren(children, childrenMap);
|
||||||
|
@ -228,8 +227,7 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
|
||||||
|
|
||||||
private static DynamicNode duplicateDynamicNode(
|
private static DynamicNode duplicateDynamicNode(
|
||||||
DynamicNode node, Map<String, List<DynamicNode>> lookupMap) {
|
DynamicNode node, Map<String, List<DynamicNode>> lookupMap) {
|
||||||
if (node instanceof DynamicContainer) {
|
if (node instanceof DynamicContainer container) {
|
||||||
DynamicContainer container = (DynamicContainer) node;
|
|
||||||
Stream<DynamicNode> children =
|
Stream<DynamicNode> children =
|
||||||
lookupMap.get(node.hashCode() + node.getDisplayName()).stream()
|
lookupMap.get(node.hashCode() + node.getDisplayName()).stream()
|
||||||
.map(x -> duplicateDynamicNode(x, lookupMap));
|
.map(x -> duplicateDynamicNode(x, lookupMap));
|
||||||
|
|
Loading…
Reference in New Issue