Skip to content

Commit

Permalink
Fixing sonar-findings
Browse files Browse the repository at this point in the history
  • Loading branch information
cuioss committed Feb 22, 2025
1 parent 4283de4 commit 2fbe8a3
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class MockAuthenticationFacade implements FormBasedAuthenticationFacade {
*/
@Override
public ResultObject<AuthenticatedUserInfo> login(final HttpServletRequest servletRequest,
final LoginCredentials loginCredentials) {
final LoginCredentials loginCredentials) {
requireNonNull(loginCredentials);
requireNonNull(servletRequest);
if (loginCredentials.isComplete()
Expand Down Expand Up @@ -192,14 +192,15 @@ private BaseAuthenticatedUserInfoBuilder createDefaultUserInfoBuilder() {
@Override
public boolean logout(final HttpServletRequest servletRequest) {
var oldSession = servletRequest.getSession();
var userInfo = (AuthenticatedUserInfo) oldSession.getAttribute(USER_INFO_KEY);
AuthenticatedUserInfo userInfo = null;
if (null != oldSession) {
userInfo = (AuthenticatedUserInfo) oldSession.getAttribute(USER_INFO_KEY);
oldSession.invalidate();
}
var newSession = servletRequest.getSession(true);
newSession.setAttribute(USER_INFO_KEY, NOT_LOGGED_IN);
newSession.setAttribute(USER_INFO_LOGOUT_KEY, USER_INFO_LOGOUT_KEY);
if (userInfo != null && userInfo.isAuthenticated()) {
if (null != userInfo && userInfo.isAuthenticated()) {
LOGGER.info(INFO.USER_LOGOUT.format(userInfo.getDisplayName()));
}
return true;
Expand All @@ -209,7 +210,7 @@ public boolean logout(final HttpServletRequest servletRequest) {
public AuthenticatedUserInfo retrieveCurrentAuthenticationContext(final HttpServletRequest servletRequest) {
var userInfo = (AuthenticatedUserInfo) servletRequest.getSession().getAttribute(USER_INFO_KEY);
if (null == userInfo) {
if (defaultLoggedIn.get()) {
if (Boolean.TRUE.equals(defaultLoggedIn.get())) {
var userName = defaultUserName.get();
userInfo = createDefaultUserInfoBuilder().identifier(userName).qualifiedIdentifier(userName)
.displayName(userName).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public void validate() throws ConnectionConfigurationException {
}
}

@SuppressWarnings("java:S2094") // owolff: see class comment
public static class ConnectionMetadataBuilder {
// Needed for lombok-builder plus javadoc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class FileWatcherServiceImpl implements FileWatcherService, ApplicationIn
*/
@Override
public void initialize() {
if (enabledProvider.get()) {
if (Boolean.TRUE.equals(enabledProvider.get())) {
LOGGER.debug("Initializing FileWatcherService");
if (null == watcherService) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ void shouldStartUpContainer() {
try (final var weld = new Weld().initialize()) {
assertNotNull(weld.select(BeanManager.class),
"Unable to acquire an instance of javax.enterprise.inject.spi.BeanManager");

/*
* final Set<Bean<?>> fileConfigSourceInstances = CDI.current().getBeanManager()
* .getBeans(FileConfigurationSource.class,
* PortalConfigurationSource.Literal.INSTANCE);
* assertFalse(fileConfigSourceInstances.isEmpty(),
* "FileConfigurationSource instances not registered in CDI");
*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
import static de.cuioss.portal.configuration.PortalConfigurationKeys.THEME_DEFAULT;
import static de.cuioss.portal.configuration.util.ConfigurationHelper.resolveConfigProperty;
import static de.cuioss.portal.configuration.util.ConfigurationHelper.resolveConfigPropertyOrThrow;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

@EnablePortalConfigurationLocal
@EnableAutoWeld
Expand Down Expand Up @@ -190,7 +195,7 @@ void shouldUseEnvPropertyFirst() {

assertTrue(
StreamSupport.stream(ConfigProvider.getConfig().getConfigSources().spliterator(), false)
.anyMatch(clazz -> clazz instanceof TestEnvConfigSource),
.anyMatch(TestEnvConfigSource.class::isInstance),
"TestEnvConfigSource class not available in configuration system");

TestEnvConfigSource.getAdditionalProperties().put(ENV_KEY, "ENV");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static class TestInitializer implements ApplicationInitializer {

@Override
public void initialize() {
// Noop implementation: Test only
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* Simple Mock variant of {@link MetricRegistry}. Partially implemented.
Expand Down Expand Up @@ -147,7 +146,7 @@ public <T extends Number> Gauge<T> gauge(MetricID metricID, Supplier<T> supplier
@Override
public <T extends Number> Gauge<T> gauge(Metadata metadata, Supplier<T> supplier, Tag... tags) {
metricMap.put(new MetricID(metadata.getName()), (Gauge) () -> null);
LOGGER.info("Gauge for metric '%s'", metadata.getName(), CollectionLiterals.mutableList(tags).stream().map(tag -> tag.getTagName() + "=" + tag.getTagValue()).collect(Collectors.toList()));
LOGGER.info("Gauge for metric '%s'", metadata.getName(), CollectionLiterals.mutableList(tags).stream().map(tag -> tag.getTagName() + "=" + tag.getTagValue()).toList());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* </ul>
*
* <h2>Usage Examples</h2>
*
* <p>
* Basic configuration test:
* <pre>
* public class MyConfigTest extends AbstractConfigurationKeyVerifierTest {
Expand All @@ -66,7 +66,7 @@
* }
* }
* </pre>
*
* <p>
* Custom key filtering:
* <pre>
* public class FilteredConfigTest extends AbstractConfigurationKeyVerifierTest {
Expand Down Expand Up @@ -103,9 +103,9 @@
* </ul>
*
* @author Oliver Wolff
* @since 1.0
* @see ConfigSource
* @see ConfigProvider
* @since 1.0
*/
public abstract class AbstractConfigurationKeyVerifierTest {

Expand Down Expand Up @@ -272,8 +272,6 @@ protected SortedSet<String> extractConfigurationKeys() {
return strings;
}
var foundNames = StreamSupport.stream(ConfigProvider.getConfig().getConfigSources().spliterator(), false).map(ConfigSource::getName).collect(Collectors.toSet());
fail("Unable to find any configuration source named '%s', available sources: '%s'".formatted(name, foundNames));

return null;
throw new AssertionError("Unable to find any configuration source named '%s', available sources: '%s'".formatted(name, foundNames));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class BaseAllAcceptDispatcherTest {

private static final String DEFAULT_PATH = "/hello";
static final RecordedRequest DUMMY = CombinedDispatcherTest.createRequestFor(HttpMethodMapper.GET, null, "/");
static final RecordedRequest DUMMY = CombinedDispatcherTest.createRequestFor(HttpMethodMapper.GET, "/");

@Test
void shouldDefaultToPositiveResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void shouldHandleMissingFilter() {

private void assertDispatchWithCode(CombinedDispatcher dispatcher, int httpCode, String urlPart) {
for (HttpMethodMapper mapper : HttpMethodMapper.values()) {
var request = createRequestFor(mapper, dispatcher, urlPart);
var request = createRequestFor(mapper, urlPart);
assertDoesNotThrow(() -> {
var result = dispatcher.dispatch(request);
assertTrue(result.getStatus().contains(String.valueOf(httpCode)),
Expand All @@ -82,7 +82,7 @@ private void assertDispatchWithCode(CombinedDispatcher dispatcher, int httpCode,

}

static RecordedRequest createRequestFor(HttpMethodMapper mapper, CombinedDispatcher dispatcher, String urlPart) {
static RecordedRequest createRequestFor(HttpMethodMapper mapper, String urlPart) {
return new RecordedRequest(mapper.name() + " " + urlPart + "someResource HTTP/1.1",
Headers.of("key=value", "key2=value2"), Collections.emptyList(), 0, new Buffer(), 0, new Socket(), null);
}
Expand Down

0 comments on commit 2fbe8a3

Please sign in to comment.