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

Closes #2459: Fix Code Smells #2460

Merged
merged 1 commit into from Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.sql.DataSource;
import org.apache.ibatis.jdbc.RuntimeSqlException;
Expand Down Expand Up @@ -78,9 +77,7 @@ public void dropDb() {
private List<String> parseScripts(Stream<String> scripts) {
try (Connection connection = dataSource.getConnection()) {
DB db = DB.getDB(connection);
return scripts
.map(script -> SqlReplacer.getScriptAsSql(db, now, script))
.collect(Collectors.toList());
return scripts.map(script -> SqlReplacer.getScriptAsSql(db, now, script)).toList();
} catch (SQLException e) {
throw new RuntimeSqlException("Connection to database failed.", e);
}
Expand Down
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.security.auth.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -61,7 +60,7 @@ public List<String> getGroupIds() {
.map(Principal::getName)
.filter(Objects::nonNull)
.map(this::convertAccessId)
.collect(Collectors.toList());
.toList();
}
LOGGER.trace("No groupIds found in subject!");
return Collections.emptyList();
Expand Down
Expand Up @@ -111,7 +111,7 @@ public <T> T interceptTestFactoryMethod(
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
} else if (factoryResult instanceof Stream) {
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
newChildrenForDynamicContainer = nodes.toList();
} else if (factoryResult instanceof Iterable) {
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
} else if (factoryResult instanceof Iterator) {
Expand Down Expand Up @@ -142,8 +142,11 @@ public <T> T interceptTestFactoryMethod(
Store store = getMethodLevelStore(extensionContext);
return (T)
Stream.of(annotation.value())
.peek(a -> store.put(ACCESS_IDS_STORE_KEY, a))
.map(wrapTestsInDynamicContainer);
.map(
a -> {
store.put(ACCESS_IDS_STORE_KEY, a);
return wrapTestsInDynamicContainer.apply(a);
});
}

return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
Expand Down Expand Up @@ -207,8 +210,11 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
AnnotationSupport.findRepeatableAnnotations(context.getElement(), WithAccessId.class);
Store store = getMethodLevelStore(context);
return accessIds.stream()
.peek(a -> store.put(ACCESS_IDS_STORE_KEY, a))
.map(JaasExtensionInvocationContext::new);
.map(
a -> {
store.put(ACCESS_IDS_STORE_KEY, a);
return new JaasExtensionInvocationContext(a);
});
}

// endregion
Expand Down Expand Up @@ -259,7 +265,7 @@ private static List<Principal> getPrincipals(WithAccessId withAccessId) {
return Stream.concat(
Stream.of(withAccessId.user()).map(UserPrincipal::new),
Arrays.stream(withAccessId.groups()).map(GroupPrincipal::new))
.collect(Collectors.toList());
.toList();
}
return Collections.emptyList();
}
Expand Down
Expand Up @@ -8,7 +8,6 @@
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.internal.util.ReflectionUtil;

Expand Down Expand Up @@ -43,6 +42,6 @@ protected static List<String> splitStringAndTrimElements(String str, String sepa
return Arrays.stream(str.split(Pattern.quote(separator)))
.filter(not(String::isEmpty))
.map(String::trim)
.collect(Collectors.toList());
.toList();
}
}
Expand Up @@ -199,7 +199,8 @@ public int hashCode() {

@Override
public boolean equals(Object o) {
return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items);
return (o instanceof ComparableVersion comparableVersion)
&& items.equals(comparableVersion.items);
}

@Override
Expand Down
Expand Up @@ -42,8 +42,8 @@ public static List<Field> retrieveAllFields(Class<?> currentClass) {
}

public static Class<?> getRawClass(Type type) {
if (type instanceof ParameterizedType) {
return getRawClass(((ParameterizedType) type).getRawType());
if (type instanceof ParameterizedType parameterizedType) {
return getRawClass(parameterizedType.getRawType());
}
return (Class<?>) type;
}
Expand Down
Expand Up @@ -504,8 +504,8 @@ private boolean isOracleIntegrityConstraintViolation(PersistenceException e) {
}

private boolean isH2OrPostgresIntegrityConstraintViolation(PersistenceException e) {
return e.getCause() instanceof SQLException
&& ((SQLException) e.getCause()).getSQLState().equals("23503");
return e.getCause() instanceof SQLException sqlException
&& sqlException.getSQLState().equals("23503");
}

/**
Expand Down
Expand Up @@ -107,17 +107,17 @@ public <T> T interceptTestFactoryMethod(

Iterable<DynamicNode> newChildrenForDynamicContainer;
// TestFactory must have one of the following return types. See link above for further details
if (factoryResult instanceof DynamicNode) {
newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult);
if (factoryResult instanceof DynamicNode dynamicNode) {
newChildrenForDynamicContainer = Collections.singleton(dynamicNode);
} else if (factoryResult instanceof Stream) {
Stream<DynamicNode> nodes = (Stream<DynamicNode>) factoryResult;
newChildrenForDynamicContainer = nodes.collect(Collectors.toList());
} else if (factoryResult instanceof Iterable) {
newChildrenForDynamicContainer = (Iterable<DynamicNode>) factoryResult;
} else if (factoryResult instanceof Iterator) {
newChildrenForDynamicContainer = () -> (Iterator<DynamicNode>) factoryResult;
} else if (factoryResult instanceof DynamicNode[]) {
newChildrenForDynamicContainer = Arrays.asList((DynamicNode[]) factoryResult);
} else if (factoryResult instanceof DynamicNode[] dynamicNodes) {
newChildrenForDynamicContainer = Arrays.asList(dynamicNodes);
} else {
throw new SystemException(
String.format(
Expand Down Expand Up @@ -217,8 +217,7 @@ private static void persistDynamicContainerChildren(
Iterable<DynamicNode> nodes, Map<String, List<DynamicNode>> childrenMap) {
nodes.forEach(
node -> {
if (node instanceof DynamicContainer) {
DynamicContainer container = (DynamicContainer) node;
if (node instanceof DynamicContainer container) {
List<DynamicNode> children = container.getChildren().collect(Collectors.toList());
childrenMap.put(container.hashCode() + container.getDisplayName(), children);
persistDynamicContainerChildren(children, childrenMap);
Expand All @@ -228,8 +227,7 @@ private static void persistDynamicContainerChildren(

private static DynamicNode duplicateDynamicNode(
DynamicNode node, Map<String, List<DynamicNode>> lookupMap) {
if (node instanceof DynamicContainer) {
DynamicContainer container = (DynamicContainer) node;
if (node instanceof DynamicContainer container) {
Stream<DynamicNode> children =
lookupMap.get(node.hashCode() + node.getDisplayName()).stream()
.map(x -> duplicateDynamicNode(x, lookupMap));
Expand Down