From a0a3245969344d498b3addd562d58889928c7e13 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Sun, 28 Jul 2024 16:31:55 -0300 Subject: [PATCH] fix code smells reported by sonarlint --- .../GatewaySharedAuhenticationTest.java | 25 ++++---- ...onmentAdminAuthenticationProviderTest.java | 4 +- ...GsCloudLayerGroupContainmentCacheTest.java | 2 +- ...configConfigRepositoryConformanceTest.java | 7 +-- .../config/PgconfigUpdateSequenceTest.java | 3 +- .../resource/PgconfigResourceTest.java | 10 +--- .../support/PgConfigTestContainer.java | 1 + .../cache/CachingGeoServerFacadeTest.java | 60 +++++++++---------- .../event/bus/BusAmqpIntegrationTests.java | 36 ++++++----- .../bus/ConfigRemoteApplicationEventsIT.java | 1 + .../catalog/PatchSerializationTest.java | 6 +- .../plugin/CatalogConformanceTest.java | 40 +++++++++---- .../catalog/plugin/XmlCatalogInfoLookup.java | 8 +-- .../plugin/locking/LockingCatalogTest.java | 15 ++--- .../GeoServerConfigConformanceTest.java | 13 ++-- ...TileLayerCatalogAutoConfigurationTest.java | 8 --- .../core/GwcCoreAutoConfigurationTest.java | 5 +- .../GeoServerTileLayerInfoMapperTest.java | 5 +- .../backend/pgconfig/TileLayerMocking.java | 3 +- .../AzureBlobStoreXmlConfigurationTest.java | 8 +-- .../CloudGwcXmlConfigurationTest.java | 8 +-- .../ResourceStoreTileLayerCatalogTest.java | 3 +- 22 files changed, 132 insertions(+), 139 deletions(-) diff --git a/src/apps/infrastructure/gateway/src/test/java/org/geoserver/cloud/security/gateway/sharedauth/GatewaySharedAuhenticationTest.java b/src/apps/infrastructure/gateway/src/test/java/org/geoserver/cloud/security/gateway/sharedauth/GatewaySharedAuhenticationTest.java index 79799b08a..f6df504ed 100644 --- a/src/apps/infrastructure/gateway/src/test/java/org/geoserver/cloud/security/gateway/sharedauth/GatewaySharedAuhenticationTest.java +++ b/src/apps/infrastructure/gateway/src/test/java/org/geoserver/cloud/security/gateway/sharedauth/GatewaySharedAuhenticationTest.java @@ -188,7 +188,7 @@ static void registerRoutes(DynamicPropertyRegistry registry) { private URI getcapabilities; @BeforeEach - void setUp(WireMockRuntimeInfo runtimeInfo) throws Exception { + void setUp(WireMockRuntimeInfo runtimeInfo) { StubMapping weblogin = buildFrom(WEB_LOGIN_SPEC); StubMapping weblogout = buildFrom(WEB_LOGOUT_SPEC); StubMapping wmscaps = buildFrom(WMS_GETCAPS); @@ -199,9 +199,9 @@ void setUp(WireMockRuntimeInfo runtimeInfo) throws Exception { wireMock.register(wmscaps); wireMock.register(buildFrom(DEFAULT_RESPONSE)); - login = gatewayUriOf(runtimeInfo, weblogin); - logout = gatewayUriOf(runtimeInfo, weblogout); - getcapabilities = gatewayUriOf(runtimeInfo, wmscaps); + login = gatewayUriOf(weblogin); + logout = gatewayUriOf(weblogout); + getcapabilities = gatewayUriOf(wmscaps); } /** @@ -245,8 +245,8 @@ void preFilterRemovesIncomingSharedAuthHeaders(WireMockRuntimeInfo runtimeInfo) void preFilterAppendsRequestHeadersFromSession(WireMockRuntimeInfo runtimeInfo) { // preflight, make sure the webui responsed with the headers and they're in the // session - ResponseEntity login = login(); - final String gatewaySessionId = getGatewaySessionId(login.getHeaders()); + ResponseEntity loginResponse = login(); + final String gatewaySessionId = getGatewaySessionId(loginResponse.getHeaders()); assertUserAndRolesStoredInSession(gatewaySessionId); // query the wms service with the gateway session id @@ -287,8 +287,8 @@ void preFilterAppendsRequestHeadersFromSession(WireMockRuntimeInfo runtimeInfo) @Order(3) @DisplayName("post-filter saves user and roles in session") void postFilterSavesUserAndRolesInSession(WireMockRuntimeInfo runtimeInfo) { - ResponseEntity login = login(); - final String gatewaySessionId = getGatewaySessionId(login.getHeaders()); + ResponseEntity loginResponse = login(); + final String gatewaySessionId = getGatewaySessionId(loginResponse.getHeaders()); assertUserAndRolesStoredInSession(gatewaySessionId); } @@ -299,8 +299,8 @@ void postFilterSavesUserAndRolesInSession(WireMockRuntimeInfo runtimeInfo) { void postFilterRemovesUserAndRolesFromSessionOnEmptyUserResponseHeader( WireMockRuntimeInfo runtimeInfo) { // preflight, have a session and the user and roles stored - ResponseEntity login = login(); - final String gatewaySessionId = getGatewaySessionId(login.getHeaders()); + ResponseEntity loginResponse = login(); + final String gatewaySessionId = getGatewaySessionId(loginResponse.getHeaders()); assertUserAndRolesStoredInSession(gatewaySessionId); // make a request that returns and empty string on the x-gsc-username response header @@ -354,11 +354,10 @@ private void assertUserAndRolesStoredInSession(final String gatewaySessionId) { private Map getSessionAttributes(final String gatewaySessionId) { WebSessionStore sessionStore = webSessionManager.getSessionStore(); WebSession session = sessionStore.retrieveSession(gatewaySessionId).block(); - Map attributes = session.getAttributes(); - return attributes; + return session.getAttributes(); } - private URI gatewayUriOf(WireMockRuntimeInfo runtimeInfo, StubMapping mapping) { + private URI gatewayUriOf(StubMapping mapping) { return URI.create(mapping.getRequest().getUrl()); } diff --git a/src/catalog/backends/common/src/test/java/org/geoserver/cloud/autoconfigure/security/EnvironmentAdminAuthenticationProviderTest.java b/src/catalog/backends/common/src/test/java/org/geoserver/cloud/autoconfigure/security/EnvironmentAdminAuthenticationProviderTest.java index be64125fd..020ca0bbb 100644 --- a/src/catalog/backends/common/src/test/java/org/geoserver/cloud/autoconfigure/security/EnvironmentAdminAuthenticationProviderTest.java +++ b/src/catalog/backends/common/src/test/java/org/geoserver/cloud/autoconfigure/security/EnvironmentAdminAuthenticationProviderTest.java @@ -180,8 +180,6 @@ protected UsernamePasswordAuthenticationToken userNamePasswordToken( protected EnvironmentAdminAuthenticationProvider envAuthProvider( AssertableApplicationContext context) { - EnvironmentAdminAuthenticationProvider provider = - context.getBean(EnvironmentAdminAuthenticationProvider.class); - return provider; + return context.getBean(EnvironmentAdminAuthenticationProvider.class); } } diff --git a/src/catalog/backends/common/src/test/java/org/geoserver/security/impl/GsCloudLayerGroupContainmentCacheTest.java b/src/catalog/backends/common/src/test/java/org/geoserver/security/impl/GsCloudLayerGroupContainmentCacheTest.java index bd0cf8562..0d2600ca6 100644 --- a/src/catalog/backends/common/src/test/java/org/geoserver/security/impl/GsCloudLayerGroupContainmentCacheTest.java +++ b/src/catalog/backends/common/src/test/java/org/geoserver/security/impl/GsCloudLayerGroupContainmentCacheTest.java @@ -153,7 +153,7 @@ private static void addWorkspaceNamespace(String wsName) { } @BeforeEach - public void setupLayerGrups() throws InterruptedException { + public void setupLayerGrups() { LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES)); LayerInfo forests = catalog.getLayerByName(getLayerId(MockData.FORESTS)); LayerInfo roads = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); diff --git a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigConfigRepositoryConformanceTest.java b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigConfigRepositoryConformanceTest.java index dd62a804f..9824ff752 100644 --- a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigConfigRepositoryConformanceTest.java +++ b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigConfigRepositoryConformanceTest.java @@ -9,7 +9,6 @@ import org.geoserver.cloud.backend.pgconfig.support.PgConfigTestContainer; import org.geoserver.config.GeoServer; import org.geoserver.config.GeoServerConfigConformanceTest; -import org.geoserver.config.plugin.GeoServerImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.testcontainers.junit.jupiter.Container; @@ -19,6 +18,7 @@ * @since 1.4 */ @Testcontainers(disabledWithoutDocker = true) +@SuppressWarnings("java:S2187") class PgconfigConfigRepositoryConformanceTest extends GeoServerConfigConformanceTest { @Container static PgConfigTestContainer container = new PgConfigTestContainer<>(); @@ -31,14 +31,13 @@ public void setUp() { } @AfterEach - void cleanDb() throws Exception { + void cleanDb() { container.tearDown(); } protected @Override GeoServer createGeoServer() { PgconfigBackendBuilder builder = new PgconfigBackendBuilder(container.getDataSource()); Catalog catalog = builder.createCatalog(); - GeoServerImpl gs = builder.createGeoServer(catalog); - return gs; + return builder.createGeoServer(catalog); } } diff --git a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigUpdateSequenceTest.java b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigUpdateSequenceTest.java index 1183f395c..1b3565eb1 100644 --- a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigUpdateSequenceTest.java +++ b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/config/PgconfigUpdateSequenceTest.java @@ -18,6 +18,7 @@ * @since 1.4 */ @Testcontainers(disabledWithoutDocker = true) +@SuppressWarnings("java:S2187") class PgconfigUpdateSequenceTest implements UpdateSequenceConformanceTest { @Container static PgConfigTestContainer container = new PgConfigTestContainer<>(); @@ -35,7 +36,7 @@ public void init() { } @AfterEach - void cleanDb() throws Exception { + void cleanDb() { container.tearDown(); } diff --git a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/resource/PgconfigResourceTest.java b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/resource/PgconfigResourceTest.java index 4056a26d3..e4e5e5e1a 100644 --- a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/resource/PgconfigResourceTest.java +++ b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/resource/PgconfigResourceTest.java @@ -64,9 +64,9 @@ @RunWith(Theories.class) public class PgconfigResourceTest extends ResourceTheoryTest { - public @ClassRule static PgConfigTestContainer container = new PgConfigTestContainer<>(); + @ClassRule public static PgConfigTestContainer container = new PgConfigTestContainer<>(); - public @Rule TemporaryFolder tmpDir = new TemporaryFolder(); + @Rule public TemporaryFolder tmpDir = new TemporaryFolder(); private PgconfigResourceStore store; private File cacheDirectory; @@ -445,11 +445,7 @@ INSERT INTO resourcestore (parentid, "type", path, content) private Set replace(String oldParent, String newParent, Set children) { return children.stream() - .map( - p -> { - String newpath = newParent + p.substring(oldParent.length()); - return newpath; - }) + .map(p -> newParent + p.substring(oldParent.length())) .collect(Collectors.toCollection(TreeSet::new)); } diff --git a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/support/PgConfigTestContainer.java b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/support/PgConfigTestContainer.java index f53085ccb..414965887 100644 --- a/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/support/PgConfigTestContainer.java +++ b/src/catalog/backends/pgconfig/src/test/java/org/geoserver/cloud/backend/pgconfig/support/PgConfigTestContainer.java @@ -29,6 +29,7 @@ * * @since 1.6 */ +@SuppressWarnings("java:S119") public class PgConfigTestContainer> extends PostgreSQLContainer { diff --git a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java index 7a086998f..9d162f0ac 100644 --- a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java +++ b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java @@ -82,7 +82,7 @@ class CachingGeoServerFacadeTest { private @Autowired CacheManager cacheManager; private Cache cache; private GeoServerInfo global; - private WorkspaceInfo ws; + private WorkspaceInfo workspace; private SettingsInfo settings; private TestService1 service1; private TestService2 service2; @@ -96,9 +96,9 @@ public static interface TestService2 extends ServiceInfo {} public @BeforeEach void before() { global = stub(GeoServerInfo.class); - ws = stub(WorkspaceInfo.class); + workspace = stub(WorkspaceInfo.class); settings = stub(SettingsInfo.class); - when(settings.getWorkspace()).thenReturn(ws); + when(settings.getWorkspace()).thenReturn(workspace); logging = stub(LoggingInfo.class); service1 = stub(TestService1.class, 1); @@ -110,8 +110,8 @@ public static interface TestService2 extends ServiceInfo {} wsService2 = stub(TestService2.class, 2); when(wsService1.getName()).thenReturn("service1"); when(wsService2.getName()).thenReturn("service2"); - when(wsService1.getWorkspace()).thenReturn(ws); - when(wsService2.getWorkspace()).thenReturn(ws); + when(wsService1.getWorkspace()).thenReturn(workspace); + when(wsService2.getWorkspace()).thenReturn(workspace); when(mock.getGlobal()).thenReturn(global); when(mock.getLogging()).thenReturn(logging); @@ -124,25 +124,25 @@ public static interface TestService2 extends ServiceInfo {} when(mock.getService(service2.getId(), TestService2.class)).thenReturn(service2); doReturn(Arrays.asList(service1, service2)).when(mock).getServices(); - when(mock.getService(ws, TestService1.class)).thenReturn(wsService1); - when(mock.getService(ws, TestService2.class)).thenReturn(wsService2); - doReturn(Arrays.asList(wsService1, wsService2)).when(mock).getServices(ws); + when(mock.getService(workspace, TestService1.class)).thenReturn(wsService1); + when(mock.getService(workspace, TestService2.class)).thenReturn(wsService2); + doReturn(Arrays.asList(wsService1, wsService2)).when(mock).getServices(workspace); when(mock.getServiceByName(service1.getName(), ServiceInfo.class)).thenReturn(service1); when(mock.getServiceByName(service1.getName(), TestService1.class)).thenReturn(service1); when(mock.getServiceByName(service2.getName(), ServiceInfo.class)).thenReturn(service1); when(mock.getServiceByName(service2.getName(), TestService2.class)).thenReturn(service2); - when(mock.getServiceByName(wsService1.getName(), ws, ServiceInfo.class)) + when(mock.getServiceByName(wsService1.getName(), workspace, ServiceInfo.class)) .thenReturn(wsService1); - when(mock.getServiceByName(wsService1.getName(), ws, TestService1.class)) + when(mock.getServiceByName(wsService1.getName(), workspace, TestService1.class)) .thenReturn(wsService1); - when(mock.getServiceByName(wsService2.getName(), ws, ServiceInfo.class)) + when(mock.getServiceByName(wsService2.getName(), workspace, ServiceInfo.class)) .thenReturn(wsService1); - when(mock.getServiceByName(wsService2.getName(), ws, TestService2.class)) + when(mock.getServiceByName(wsService2.getName(), workspace, TestService2.class)) .thenReturn(wsService2); - when(mock.getSettings(ws)).thenReturn(settings); + when(mock.getSettings(workspace)).thenReturn(settings); this.cache = cacheManager.getCache(CACHE_NAME); this.cache.clear(); } @@ -218,14 +218,14 @@ void onLoggingInfoSetEvent() { @Test void onSettingsInfoModifyEvent() { - caching.getSettings(ws); + caching.getSettings(workspace); final Object idKey = settings.getId(); - final Object wsKey = CachingGeoServerFacade.settingsKey(ws); + final Object wsKey = CachingGeoServerFacade.settingsKey(workspace); assertThat(cache.get(idKey)).isNotNull(); assertThat(cache.get(wsKey)).isNotNull(); SettingsModified event = event(SettingsModified.class, settings.getId(), SETTINGS); - final String wsid = ws.getId(); + final String wsid = workspace.getId(); when(event.getWorkspaceId()).thenReturn(wsid); caching.onSettingsInfoModifyEvent(event); @@ -235,14 +235,14 @@ void onSettingsInfoModifyEvent() { @Test void onSettingsInfoRemoveEvent() { - caching.getSettings(ws); + caching.getSettings(workspace); final Object idKey = settings.getId(); - final Object wsKey = CachingGeoServerFacade.settingsKey(ws); + final Object wsKey = CachingGeoServerFacade.settingsKey(workspace); assertThat(cache.get(idKey)).isNotNull(); assertThat(cache.get(wsKey)).isNotNull(); SettingsRemoved event = event(SettingsRemoved.class, settings.getId(), SETTINGS); - final String wsid = ws.getId(); + final String wsid = workspace.getId(); when(event.getWorkspaceId()).thenReturn(wsid); caching.onSettingsInfoRemoveEvent(event); @@ -391,29 +391,29 @@ void testSaveGeoServerInfo() { @Test void testGetSettings() { - assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(ws); - assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); + assertSameTimesN(settings, () -> caching.getSettings(workspace), 3); + verify(mock, times(1)).getSettings(workspace); + assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(workspace))); } @Test void testSaveSettingsInfo() { - assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(ws); - assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); + assertSameTimesN(settings, () -> caching.getSettings(workspace), 3); + verify(mock, times(1)).getSettings(workspace); + assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(workspace))); caching.save(settings); - assertNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); + assertNull(cache.get(CachingGeoServerFacade.settingsKey(workspace))); } @Test void testRemoveSettingsInfo() { - assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(ws); - assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); + assertSameTimesN(settings, () -> caching.getSettings(workspace), 3); + verify(mock, times(1)).getSettings(workspace); + assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(workspace))); caching.remove(settings); - assertNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); + assertNull(cache.get(CachingGeoServerFacade.settingsKey(workspace))); } @Test diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java index cefc351f8..df8449445 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java @@ -32,7 +32,6 @@ import org.geoserver.catalog.LayerGroupInfo; import org.geoserver.catalog.LayerInfo; import org.geoserver.catalog.NamespaceInfo; -import org.geoserver.catalog.PublishedInfo; import org.geoserver.catalog.ResourceInfo; import org.geoserver.catalog.StoreInfo; import org.geoserver.catalog.StyleInfo; @@ -264,8 +263,7 @@ protected PropertyDiff resolveExpectedDiff(T proxy) { List oldValues = h.getOldValues(); assertFalse(propertyNames.isEmpty(), "Test should change at least one property"); - PropertyDiff expected = PropertyDiff.valueOf(propertyNames, oldValues, newValues); - return expected; + return PropertyDiff.valueOf(propertyNames, oldValues, newValues); } @SuppressWarnings("unchecked") @@ -353,7 +351,7 @@ protected void assertRemoteEvent(T info, RemoteGeoServerEvent b assertThat(infoType.isInstance(object)).isTrue(); assertThat(object.getId()).isEqualTo(info.getId()); - assertResolved(object, Info.class); + assertResolved(object); } if (event instanceof InfoModified modifyEvent) { @@ -361,37 +359,37 @@ protected void assertRemoteEvent(T info, RemoteGeoServerEvent b } } - protected void assertResolved(Info info, Class expected) { + protected void assertResolved(Info info) { if (null == info) return; if (ProxyUtils.isResolvingProxy(info)) return; switch (info) { case StoreInfo store: assertCatalogSet(store, store::getCatalog); - assertResolved(store.getWorkspace(), WorkspaceInfo.class); + assertResolved(store.getWorkspace()); break; case ResourceInfo resource: assertCatalogSet(resource, resource::getCatalog); - assertResolved(resource.getNamespace(), NamespaceInfo.class); - assertResolved(resource.getStore(), StoreInfo.class); + assertResolved(resource.getNamespace()); + assertResolved(resource.getStore()); break; case StyleInfo style: - assertResolved(style.getWorkspace(), WorkspaceInfo.class); + assertResolved(style.getWorkspace()); break; case LayerInfo layer: - assertResolved(layer.getDefaultStyle(), StyleInfo.class); - assertResolved(layer.getResource(), ResourceInfo.class); + assertResolved(layer.getDefaultStyle()); + assertResolved(layer.getResource()); break; case LayerGroupInfo lg: - assertResolved(lg.getWorkspace(), WorkspaceInfo.class); - assertResolved(lg.getRootLayer(), LayerInfo.class); - assertResolved(lg.getRootLayerStyle(), StyleInfo.class); - lg.getStyles().forEach(s -> assertResolved(s, StyleInfo.class)); - lg.getLayers().forEach(l -> assertResolved(l, PublishedInfo.class)); - lg.getLayerGroupStyles().forEach(lgs -> assertResolved(lgs, LayerGroupStyle.class)); + assertResolved(lg.getWorkspace()); + assertResolved(lg.getRootLayer()); + assertResolved(lg.getRootLayerStyle()); + lg.getStyles().forEach(this::assertResolved); + lg.getLayers().forEach(this::assertResolved); + lg.getLayerGroupStyles().forEach(this::assertResolved); break; case LayerGroupStyle lgs: - lgs.getLayers().forEach(l -> assertResolved(l, PublishedInfo.class)); - lgs.getStyles().forEach(s -> assertResolved(s, StyleInfo.class)); + lgs.getLayers().forEach(this::assertResolved); + lgs.getStyles().forEach(this::assertResolved); break; case NamespaceInfo ns: break; diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java index d00b70276..b8548dd9e 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java @@ -40,6 +40,7 @@ class ConfigRemoteApplicationEventsIT extends BusAmqpIntegrationTests { + @Override @BeforeEach public void before() { super.before(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java index 7e7c0f2d9..c33d66edc 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java @@ -773,8 +773,7 @@ private Patch patch(String name, Object value) { } protected Patch resolve(Patch decoded) { - Patch resolved = proxyResolver.resolve(decoded); - return resolved; + return proxyResolver.resolve(decoded); } private Patch roundtrip(Patch patch) throws JsonProcessingException { @@ -807,8 +806,7 @@ private Patch roundtrip(Patch patch) throws JsonProcessingException { protected String asJson(Patch patch) throws JsonProcessingException { ObjectWriter writer = objectMapper.writer(); writer = writer.withDefaultPrettyPrinter(); - String encoded = writer.writeValueAsString(patch); - return encoded; + return writer.writeValueAsString(patch); } private T forceProxy(T info, Class iface) { diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java index 643bf114d..1d58619be 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java @@ -1116,6 +1116,7 @@ private void verifyNamespaceOfStoreResources(StoreInfo store) { } @Test + @SuppressWarnings("java:S5961") void testDataStoreEvents() { addWorkspace(); @@ -2179,7 +2180,6 @@ void testStyleEvents() { void testProxyBehaviour() { testAddLayer(); - // l = catalog.getLayerByName( "layerName"); LayerInfo l = catalog.getLayerByName(data.featureTypeA.getName()); assertTrue(l instanceof Proxy); @@ -2287,7 +2287,7 @@ void testAddWMTSStore() { assertEquals(2, catalog.getStores(WMTSStoreInfo.class).size()); } - protected int GET_LAYER_BY_ID_WITH_CONCURRENT_ADD_TEST_COUNT = 500; + protected int getLayerByIdWithConcurrentAddTestCount = 500; private static final int GET_LAYER_BY_ID_WITH_CONCURRENT_ADD_THREAD_COUNT = 10; /** @@ -2329,7 +2329,7 @@ void testGetLayerByIdWithConcurrentAdd() throws Exception { // wait for all threads to reach latch in order to maximize likelihood of contention ready.await(); - for (int i = 0; i < GET_LAYER_BY_ID_WITH_CONCURRENT_ADD_TEST_COUNT; i++) { + for (int i = 0; i < getLayerByIdWithConcurrentAddTestCount; i++) { catalog.getLayer(id); } @@ -2811,29 +2811,37 @@ protected static class TestListener implements CatalogListener { public List postModified = new CopyOnWriteArrayList<>(); public List removed = new CopyOnWriteArrayList<>(); + @Override public void handleAddEvent(CatalogAddEvent event) { added.add(event); } + @Override public void handleModifyEvent(CatalogModifyEvent event) { modified.add(event); } + @Override public void handlePostModifyEvent(CatalogPostModifyEvent event) { postModified.add(event); } + @Override public void handleRemoveEvent(CatalogRemoveEvent event) { removed.add(event); } - public void reloaded() {} + @Override + public void reloaded() { + // no-op + } } protected static class ExceptionThrowingListener implements CatalogListener { public boolean throwCatalogException; + @Override public void handleAddEvent(CatalogAddEvent event) throws CatalogException { if (throwCatalogException) { throw new CatalogException("expected, testing Catalog's CatalogException handling"); @@ -2842,13 +2850,25 @@ public void handleAddEvent(CatalogAddEvent event) throws CatalogException { } } - public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException {} + @Override + public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException { + // no-op + } - public void handlePostModifyEvent(CatalogPostModifyEvent event) throws CatalogException {} + @Override + public void handlePostModifyEvent(CatalogPostModifyEvent event) throws CatalogException { + // no-op + } - public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException {} + @Override + public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { + // no-op + } - public void reloaded() {} + @Override + public void reloaded() { + // no-op + } } class LayerAddRunner extends RunnerBase { @@ -2862,7 +2882,7 @@ protected LayerAddRunner(CountDownLatch ready, CountDownLatch done, int idx) { protected void runInternal() { CatalogFactory factory = catalog.getFactory(); - for (int i = 0; i < GET_LAYER_BY_ID_WITH_CONCURRENT_ADD_TEST_COUNT; i++) { + for (int i = 0; i < getLayerByIdWithConcurrentAddTestCount; i++) { // GR: Adding a new feature type info too, we can't really add multiple layers per // feature type yet. Setting the name of the layer changes the name of the resource, // then all previous layers for that resource get screwed @@ -2880,7 +2900,6 @@ protected void runInternal() { } } } - ; @Test void testGet() { @@ -2967,6 +2986,7 @@ void testGet() { } @Test + @SuppressWarnings("java:S1854") void testListPredicate() { addDataStore(); addNamespace(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java index 9b1f522d5..254aaa555 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java @@ -172,11 +172,9 @@ public boolean canSortBy(String propertyName) { public Stream findAll(Query query) { Comparator comparator = toComparator(query); Predicate predicate = toPredicate(query.getFilter()); - Stream stream = - list(query.getType(), predicate, comparator) - .skip(query.offset().orElse(0)) - .limit(query.count().orElse(Integer.MAX_VALUE)); - return stream; + return list(query.getType(), predicate, comparator) + .skip(query.offset().orElse(0)) + .limit(query.count().orElse(Integer.MAX_VALUE)); } @Override diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java index dc4b902cb..0b268b9a3 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java @@ -127,15 +127,12 @@ void preAcquiredLockMultiThreadTest() { created // .stream() .map( - list -> { - List sublist = - list.stream() - .map(CatalogInfo::getId) - .map(catalog::findById) - .map(Optional::orElseThrow) - .toList(); - return sublist; - }); + list -> + list.stream() + .map(CatalogInfo::getId) + .map(catalog::findById) + .map(Optional::orElseThrow) + .toList()); updated // .parallel() // diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java index c220971a8..c3c1c8b9f 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java @@ -15,8 +15,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import org.geoserver.catalog.WorkspaceInfo; import org.geoserver.config.impl.GeoServerImpl; @@ -108,11 +108,10 @@ void testAddService() { ServiceInfo s2 = createService(); ((ServiceInfoImpl) s2).setId(service.getId()); - try { - geoServer.add(s2); - fail("adding service with duplicate id should throw exception"); - } catch (Exception e) { - } + assertThrows( + RuntimeException.class, + () -> geoServer.add(s2), + "adding service with duplicate id should throw exception"); ServiceInfo s = geoServer.getServiceByName("wms", ServiceInfo.class); assertNotSame(service, s); @@ -172,6 +171,7 @@ static class TestListener extends ConfigurationListenerAdapter { List sOldValues = new ArrayList<>(); List sNewValues = new ArrayList<>(); + @Override public void handleGlobalChange( GeoServerInfo global, List propertyNames, @@ -182,6 +182,7 @@ public void handleGlobalChange( gNewValues.addAll(newValues); } + @Override public void handleServiceChange( ServiceInfo service, List propertyNames, diff --git a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfigurationTest.java b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfigurationTest.java index 37196af5f..3ed41b1a6 100644 --- a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfigurationTest.java +++ b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfigurationTest.java @@ -23,9 +23,7 @@ import org.geowebcache.config.TileLayerConfiguration; import org.geowebcache.config.XMLConfiguration; import org.geowebcache.storage.DefaultStorageFinder; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -47,12 +45,6 @@ class PgconfigTileLayerCatalogAutoConfigurationTest { @TempDir File cacheDir; private WebApplicationContextRunner runner; - @BeforeAll - static void setUpBeforeClass() {} - - @AfterAll - static void tearDownAfterClass() {} - @BeforeEach void setUp() { runner = diff --git a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java index eac18336d..87f9136e9 100644 --- a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java +++ b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java @@ -40,7 +40,7 @@ class GwcCoreAutoConfigurationTest { * @throws java.lang.Exception */ @BeforeEach - void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) { GeoServerExtensionsHelper.clear(); runner = GeoWebCacheContextRunner.newMinimalGeoWebCacheContextRunner(tmpDir); } @@ -66,7 +66,7 @@ void defaultCacheDirectoryIsAFile(@TempDir File tmpDir) throws IOException { } @Test - void contextLoads() throws IOException { + void contextLoads() { runner.run( context -> { GeoServerExtensionsHelper.init(context); @@ -77,7 +77,6 @@ void contextLoads() throws IOException { "gwcGeoserverConfigurationInitializer", GwcGeoserverConfigurationInitializer.class) .isInstanceOf(GwcGeoserverConfigurationInitializer.class); - ; assertThat(context.isTypeMatch("gwcXmlConfig", CloudGwcXmlConfiguration.class)) .isTrue(); diff --git a/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/GeoServerTileLayerInfoMapperTest.java b/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/GeoServerTileLayerInfoMapperTest.java index af9388569..c5b85bb5a 100644 --- a/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/GeoServerTileLayerInfoMapperTest.java +++ b/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/GeoServerTileLayerInfoMapperTest.java @@ -236,9 +236,6 @@ private GeoServerTileLayerInfoImpl roundtripTest() { private GeoServerTileLayerInfoImpl roundtripTest(GeoServerTileLayer layer) { TileLayerInfo pgInfo = mapper.map(layer); - - GeoServerTileLayerInfoImpl roundtripped = mapper.map(pgInfo); - - return roundtripped; + return mapper.map(pgInfo); } } diff --git a/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/TileLayerMocking.java b/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/TileLayerMocking.java index 33697bf8d..f10e6fd62 100644 --- a/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/TileLayerMocking.java +++ b/src/gwc/backends/pgconfig/src/test/java/org/geoserver/cloud/gwc/backend/pgconfig/TileLayerMocking.java @@ -74,8 +74,7 @@ public String workspaceName(PublishedInfo published) { public GeoServerTileLayer geoServerTileLayer(PublishedInfo published) { GeoServerTileLayerInfo tileLayerInfo = TileLayerInfoUtil.loadOrCreate(published, new GWCConfig()); - GeoServerTileLayer tl = new GeoServerTileLayer(published, gridsets, tileLayerInfo); - return tl; + return new GeoServerTileLayer(published, gridsets, tileLayerInfo); } public TileLayerInfo pgLayerInfo(PublishedInfo info) { diff --git a/src/gwc/blobstores/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java b/src/gwc/blobstores/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java index e13dda9d2..47302a387 100644 --- a/src/gwc/blobstores/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java +++ b/src/gwc/blobstores/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java @@ -70,12 +70,12 @@ private CloudGwcXmlConfiguration createStubConfig() throws GeoWebCacheException tmpdir.toAbsolutePath().toString(), (DefaultStorageFinder) null); - CloudGwcXmlConfiguration config = + CloudGwcXmlConfiguration xmlConfig = new CloudGwcXmlConfiguration(appCtx, inFac, mockEventPublisher::set); GridSetBroker broker = new GridSetBroker(List.of(defaultGridsets)); - config.setGridSetBroker(broker); - config.afterPropertiesSet(); - return config; + xmlConfig.setGridSetBroker(broker); + xmlConfig.afterPropertiesSet(); + return xmlConfig; } @Test diff --git a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java index 016202eef..6b8a75c53 100644 --- a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java +++ b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java @@ -75,12 +75,12 @@ private CloudGwcXmlConfiguration createStubConfig() throws GeoWebCacheException tmpdir.toAbsolutePath().toString(), (DefaultStorageFinder) null); - CloudGwcXmlConfiguration config = + CloudGwcXmlConfiguration xmlConfig = new CloudGwcXmlConfiguration(appCtx, inFac, mockEventPublisher::set); GridSetBroker broker = new GridSetBroker(List.of(defaultGridsets)); - config.setGridSetBroker(broker); - config.afterPropertiesSet(); - return config; + xmlConfig.setGridSetBroker(broker); + xmlConfig.afterPropertiesSet(); + return xmlConfig; } @Test diff --git a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java index 2d1e8c191..5764e0b2f 100644 --- a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java +++ b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java @@ -24,7 +24,6 @@ import org.springframework.web.context.WebApplicationContext; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -162,7 +161,7 @@ void testSaveWithEmptyStyleParamFilter() { } @Test - void testEvents() throws IOException, InterruptedException { + void testEvents() { AtomicBoolean hasBeenCreated = new AtomicBoolean(false); AtomicBoolean hasBeenModified = new AtomicBoolean(false); AtomicBoolean hasBeenDeleted = new AtomicBoolean(false);