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

Apply idea code analysis suggestions #1406

Merged
merged 1 commit into from
Nov 15, 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.
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 @@ -20,15 +20,12 @@ public class PriceConsumer {
public String getLastPrice() {
try (JMSContext context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE);
JMSConsumer consumer = context.createConsumer(context.createQueue("prices"))) {
while (true) {
Message message = consumer.receive();
if (message == null) {
// receive returns `null` if the JMSConsumer is closed
return "";
}

return message.getBody(String.class);
Message message = consumer.receive();
if (message == null) {
// receive returns `null` if the JMSConsumer is closed
return "";
}
return message.getBody(String.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.jms.JMSContext;
import jakarta.jms.Session;

import io.quarkus.logging.Log;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;

Expand Down Expand Up @@ -41,7 +42,7 @@ public void run() {
try (JMSContext context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE)) {
context.createProducer().send(context.createQueue("prices"), Integer.toString(random.nextInt(PRICES_MAX)));
} catch (Exception e) {
e.printStackTrace();
Log.error("Failed to send message to queue 'prices'", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseGreetingResourceIT {
static ConsulService consul;

@QuarkusApplication
static RestService app = new RestService().withProperty("quarkus.consul-config.agent.host-port",
static final RestService app = new RestService().withProperty("quarkus.consul-config.agent.host-port",
() -> consul.getConsulEndpoint());

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class BuildTimeGreetingResourceIT {

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.consul-config.enabled", "false")
.withProperty("quarkus.http.root-path", "/root"); // property to force build app at test time.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class AbstractMysqlReusableInstance extends AbstractSqlDatabaseI
**/

@Container(image = "${mysql.image}", port = 3306, expectedLog = "port: 3306 MySQL Community Server")
public static MySqlService database = new MySqlService();
public static final MySqlService database = new MySqlService();

static Integer containerPort;

Expand All @@ -33,6 +33,5 @@ private boolean isFirstInstance() {

private void setContainerPort() {
containerPort = database.getURI().getPort();
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class DevModeMySqlDatabaseIT extends AbstractSqlDatabaseIT {
static final int MYSQL_PORT = 3306;

@Container(image = "${mysql.image}", port = MYSQL_PORT, expectedLog = "ready for connections")
static DefaultService database = new DefaultService()
static final DefaultService database = new DefaultService()
.withProperty("MYSQL_ROOT_USER", MYSQL_USER)
.withProperty("MYSQL_ROOT_PASSWORD", MYSQL_PASSWORD)
.withProperty("MYSQL_USER", MYSQL_USER)
.withProperty("MYSQL_PASSWORD", MYSQL_PASSWORD)
.withProperty("MYSQL_DATABASE", MYSQL_DATABASE);

@DevModeQuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.hibernate-orm.sql-load-script", "import-in-test.sql")
.withProperty("quarkus.datasource.username", MYSQL_USER)
.withProperty("quarkus.datasource.password", MYSQL_PASSWORD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DevModeMySqlDevServicesDatabaseIT extends AbstractSqlDatabaseIT {

@DevModeQuarkusApplication
static RestService app = new RestService();
static final RestService app = new RestService();

@Override
protected RestService getApp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class MySqlDatabaseIT extends AbstractMysqlReusableInstance {

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class MySqlReusableDatabaseIT extends AbstractMysqlReusableInstance {

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class DevModeOracleDatabaseIT extends AbstractSqlDatabaseIT {
static final int ORACLE_PORT = 1521;

@Container(image = "${oracle.image}", port = ORACLE_PORT, expectedLog = "DATABASE IS READY TO USE!")
static DefaultService database = new DefaultService()
static final DefaultService database = new DefaultService()
.withProperty("APP_USER", ORACLE_USER)
.withProperty("APP_USER_PASSWORD", ORACLE_PASSWORD)
.withProperty("ORACLE_PASSWORD", ORACLE_PASSWORD)
.withProperty("ORACLE_DATABASE", ORACLE_DATABASE);

@DevModeQuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.hibernate-orm.sql-load-script", "import-in-test.sql")
.withProperty("quarkus.datasource.username", ORACLE_USER)
.withProperty("quarkus.datasource.password", ORACLE_PASSWORD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DevModeOracleDevServiceDatabaseIT extends AbstractSqlDatabaseIT {

@DevModeQuarkusApplication
static RestService app = new RestService();
static final RestService app = new RestService();

@Override
protected RestService getApp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
public class OracleDatabaseIT extends AbstractSqlDatabaseIT {

@Container(image = "${oracle.image}", port = ORACLE_PORT, expectedLog = "DATABASE IS READY TO USE!")
static OracleService database = new OracleService();
static final OracleService database = new OracleService();

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DuplicatedPostgresqlDatabaseIT {
private static final int POSTGRESQL_PORT = 5432;

@Container(image = "${postgresql.image}", port = POSTGRESQL_PORT, expectedLog = "is ready")
static PostgresqlService database = new PostgresqlService();
static final PostgresqlService database = new PostgresqlService();

@QuarkusApplication
static RestService app = new RestService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class KubernetesPostgresqlIT extends AbstractSqlDatabaseIT {
private static final int POSTGRESQL_PORT = 5432;

@Container(image = "${postgresql.image}", port = POSTGRESQL_PORT, expectedLog = "is ready")
static PostgresqlService database = new PostgresqlService()
static final PostgresqlService database = new PostgresqlService()
.withProperty("PGDATA", "/tmp/psql");

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class OpenShiftPostgresqlIT extends AbstractSqlDatabaseIT {
private static final int POSTGRESQL_PORT = 5432;

@Container(image = "${postgresql.image}", port = POSTGRESQL_PORT, expectedLog = "is ready")
static PostgresqlService database = new PostgresqlService()
static final PostgresqlService database = new PostgresqlService()
.withProperty("PGDATA", "/tmp/psql");

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class PostgresqlDatabaseIT extends AbstractSqlDatabaseIT {
private static final int POSTGRESQL_PORT = 5432;

@Container(image = "${postgresql.image}", port = POSTGRESQL_PORT, expectedLog = "is ready")
static PostgresqlService database = new PostgresqlService();
static final PostgresqlService database = new PostgresqlService();

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.datasource.username", database.getUser())
.withProperty("quarkus.datasource.password", database.getPassword())
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class QuickstartUsingUsingUberJarIT {
static final RestService app = new RestService();

@Test
public void test() throws InterruptedException {
public void test() {
app.given()
.get("/hello")
.then()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TodoDemoIT {
private static final String NO_SUFFIX = "-Dquarkus.package.jar.add-runner-suffix=false";

@Container(image = "${postgresql.image}", port = 5432, expectedLog = "is ready")
static PostgresqlService database = new PostgresqlService()
static final PostgresqlService database = new PostgresqlService()
// store data in /tmp/psql as in OpenShift we don't have permissions to /var/lib/postgresql/data
.withProperty("PGDATA", "/tmp/psql");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class OpenShiftUsingExtensionAndServerlessFunqyKnEventsIT {
"Start::defaultChain::configChain::annotatedChain::lastChainLink");

@QuarkusApplication
static FunqyKnativeEventsService service = new OpenShiftExtensionFunqyKnativeEventsService()
static final FunqyKnativeEventsService service = new OpenShiftExtensionFunqyKnativeEventsService()
.withDefaultBroker()
.withTrigger().name("annotatedchain").defaultBroker().filterCloudEventType("annotated").endTrigger()
.withTrigger().name("configChain").defaultBroker().filterCloudEventType("defaultChain.output").endTrigger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DevModeGreetingResourceIT {
static final String HELLO_IN_SPANISH = "Hola";

@DevModeQuarkusApplication
static DevModeQuarkusService app = new DevModeQuarkusService();
static final DevModeQuarkusService app = new DevModeQuarkusService();

@Test
@Order(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class GreetingResourceUsingRuntimePropertiesIT {
static final String MANUEL_NAME = "manuel";

@QuarkusApplication
static RestService joseApp = new RestService().withProperty(ValidateCustomProperty.CUSTOM_PROPERTY, JOSE_NAME);
static final RestService joseApp = new RestService().withProperty(ValidateCustomProperty.CUSTOM_PROPERTY, JOSE_NAME);
@QuarkusApplication
static RestService manuelApp = new RestService().withProperty(ValidateCustomProperty.CUSTOM_PROPERTY, MANUEL_NAME);
static final RestService manuelApp = new RestService().withProperty(ValidateCustomProperty.CUSTOM_PROPERTY, MANUEL_NAME);

@Test
public void shouldSayJose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.QuarkusApplication;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import io.vertx.mutiny.ext.web.client.predicate.ResponsePredicate;

@QuarkusScenario
public class ReactiveGreetingResourceIT {
Expand All @@ -21,9 +19,11 @@ public class ReactiveGreetingResourceIT {
@Test
public void shouldSayDefaultGreeting() {
String response = app.mutiny().get("/reactive-greeting")
.expect(ResponsePredicate.status(HttpURLConnection.HTTP_OK))
.send()
.map(HttpResponse::bodyAsString)
.map(resp -> {
assertEquals(HttpURLConnection.HTTP_OK, resp.statusCode(), "Expected HTTP OK status");
return resp.bodyAsString();
})
.await().indefinitely();

assertEquals("Hello, I'm victor", response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RemoteDevModeGreetingResourceIT {
static final String HELLO_IN_SPANISH = "Hola";

@RemoteDevModeQuarkusApplication
static DevModeQuarkusService app = new DevModeQuarkusService();
static final DevModeQuarkusService app = new DevModeQuarkusService();

@Test
public void shouldUpdateResourcesAndSources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@QuarkusScenario
public class DevModeGreetingResourceIT {
@DevModeQuarkusApplication(ssl = true, certificates = @Certificate(configureKeystore = true, configureHttpServer = true, useTlsRegistry = false))
static DevModeQuarkusService app = new DevModeQuarkusService();
static final DevModeQuarkusService app = new DevModeQuarkusService();

@Test
public void shouldOpenDevUi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TlsRegistryCertificateReloadingIT {
@QuarkusApplication(ssl = true, certificates = @Certificate(clientCertificates = {
@Certificate.ClientCertificate(cnAttribute = CLIENT_CN_1)
}, configureTruststore = true, configureHttpServer = true, configureKeystore = true, prefix = CERT_PREFIX))
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.http.ssl.client-auth", "request")
.withProperty("quarkus.http.insecure-requests", "DISABLED")
.withProperty("quarkus.tls.reload-period", "2s");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class BookResource {
@Path("/{title}")
@Produces(MediaType.APPLICATION_JSON)
public Book getBook(@PathParam("title") String title) {
Book found = cache.get(title);
return found;
return cache.get(title);
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class ClientResourceIT {
private static final String OPERATION = "GET " + CLIENT_ENDPOINT;

@JaegerContainer()
static JaegerService jaeger = new JaegerService();
static final JaegerService jaeger = new JaegerService();

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.otel.exporter.otlp.traces.endpoint", jaeger::getCollectorUrl);

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class OpenTelemetryJaegerTlsIT {
private static final String OPERATION = "GET " + CLIENT_ENDPOINT;

@JaegerContainer(tls = true)
static JaegerService jaeger = new JaegerService();
static final JaegerService jaeger = new JaegerService();

@QuarkusApplication
static RestService app = new RestService()
static final RestService app = new RestService()
.withProperty("quarkus.otel.exporter.otlp.traces.tls-configuration-name", "jaeger")
.withProperty("quarkus.otel.exporter.otlp.traces.endpoint", () -> jaeger.getCollectorUrl(Protocol.HTTPS))
.withProperty("quarkus.tls.jaeger.key-store.pem.0.cert", () -> getClientCert().certPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Topology buildTopology() {

builder.stream(LOGIN_ATTEMPTS_TOPIC, Consumed.with(Serdes.String(), loginAttemptSerde))
.groupByKey()
.windowedBy(TimeWindows.of(Duration.ofSeconds(windowsLoginSec)))
.windowedBy(TimeWindows.ofSizeWithNoGrace(Duration.ofSeconds(windowsLoginSec)))
.aggregate(LoginAggregation::new,
(id, value, aggregation) -> aggregation.updateFrom(value),
Materialized.<String, LoginAggregation, WindowStore<Bytes, byte[]>> as(LOGIN_AGGREGATION_STORE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class BaseSecurityResourceIT {
static final String NORMAL_USER = "test-normal-user";

@KeycloakContainer(command = { "start-dev", "--import-realm" })
static KeycloakService keycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM, DEFAULT_REALM_BASE_PATH);
static final KeycloakService keycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM, DEFAULT_REALM_BASE_PATH);

private AuthzClient authzClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class DevModeSecurityResourceIT extends BaseSecurityResourceIT {
@DevModeQuarkusApplication
static final RestService app = new RestService()
.withProperty("quarkus.oidc.auth-server-url", () -> keycloak.getRealmUrl())
.withProperty("quarkus.oidc.auth-server-url", keycloak::getRealmUrl)
.withProperty("quarkus.oidc.client-id", CLIENT_ID_DEFAULT)
.withProperty("quarkus.oidc.credentials.secret", CLIENT_SECRET_DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SecurityResourceIT extends BaseSecurityResourceIT {

@QuarkusApplication
static final RestService app = new RestService()
.withProperty("quarkus.oidc.auth-server-url", () -> keycloak.getRealmUrl())
.withProperty("quarkus.oidc.auth-server-url", keycloak::getRealmUrl)
.withProperty("quarkus.oidc.client-id", CLIENT_ID_DEFAULT)
.withProperty("quarkus.oidc.credentials.secret", CLIENT_SECRET_DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ComputedValuesPingPongResourceIT {
@Test
public void shouldGetComputedValues() {
assertFalse(pingpong.getProperty("property.not.exists").isPresent());
assertEquals("A", pingpong.getProperty("property.without.profile").get());
assertEquals("B", pingpong.getProperty("property.with.profile").get());
assertEquals("A", pingpong.getProperty("property.without.profile").orElseThrow());
assertEquals("B", pingpong.getProperty("property.with.profile").orElseThrow());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ComputedValuesUsingCustomPropertiesPingPongResourceIT {

@Test
public void shouldGetComputedValuesFromCustomPropertiesFile() {
assertEquals("C", pingpong.getProperty("property.exists.only.in.custom.properties").get());
assertEquals("C", pingpong.getProperty("property.exists.only.in.custom.properties").orElseThrow());
}

}
Loading