Skip to content

Commit

Permalink
Sonar: rename fields idiomatically (#387)
Browse files Browse the repository at this point in the history
* Rename non-final static fields in several tests from
  DATA_SOURCE to dataSource. The field cannot be
  final b/c they are set up in the BeforeAll method.
  • Loading branch information
sleberknight authored Jul 8, 2024
1 parent 1c78d6e commit ea265f4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
@DisplayName("Jdbi3ApplicationErrorDao (H2)")
class H2Jdbi3ApplicationErrorDaoTest extends AbstractJdbi3ApplicationErrorDaoTest {

private static JdbcDataSource DATA_SOURCE;
private static JdbcDataSource dataSource;

@BeforeAll
static void beforeAll() {
var dataSourceFactory = ApplicationErrorJdbc.createInMemoryH2Database();

DATA_SOURCE = new JdbcDataSource();
DATA_SOURCE.setUrl(dataSourceFactory.getUrl());
DATA_SOURCE.setUser(dataSourceFactory.getUser());
DATA_SOURCE.setPassword(dataSourceFactory.getPassword());
dataSource = new JdbcDataSource();
dataSource.setUrl(dataSourceFactory.getUrl());
dataSource.setUser(dataSourceFactory.getUser());
dataSource.setPassword(dataSourceFactory.getPassword());
}

@AfterAll
static void afterAll() throws SQLException {
shutdownH2Database(DATA_SOURCE);
shutdownH2Database(dataSource);

DATA_SOURCE = null;
dataSource = null;
}

@RegisterExtension final Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> jdbi3DaoExtension =
Jdbi3DaoExtension.<Jdbi3ApplicationErrorDao>builder()
.daoType(Jdbi3ApplicationErrorDao.class)
.dataSource(DATA_SOURCE)
.dataSource(dataSource)
.plugin(new H2DatabasePlugin())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
@DisplayName("Jdbi3ApplicationErrorDao (SQLite)")
class SqliteJdbi3ApplicationErrorDaoTest extends AbstractJdbi3ApplicationErrorDaoTest {

private static SimpleSingleConnectionDataSource DATA_SOURCE;
private static SimpleSingleConnectionDataSource dataSource;

@BeforeAll
static void beforeAll() {
DATA_SOURCE = newInMemorySqliteDataSource();
migrateDatabase(DATA_SOURCE, "dropwizard-app-errors-migrations-sqlite.xml");
dataSource = newInMemorySqliteDataSource();
migrateDatabase(dataSource, "dropwizard-app-errors-migrations-sqlite.xml");
}

@RegisterExtension
final Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> jdbi3DaoExtension =
Jdbi3DaoExtension.<Jdbi3ApplicationErrorDao>builder()
.daoType(Jdbi3ApplicationErrorDao.class)
.dataSource(DATA_SOURCE)
.dataSource(dataSource)
.build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
@DisplayName("JdbcApplicationErrorDao (H2)")
public class H2JdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTest {

private static SimpleSingleConnectionDataSource DATA_SOURCE;
private static SimpleSingleConnectionDataSource dataSource;

@BeforeAll
static void beforeAll() {
var dataSourceFactory = ApplicationErrorJdbc.createInMemoryH2Database();

DATA_SOURCE = new SimpleSingleConnectionDataSource(
dataSource = new SimpleSingleConnectionDataSource(
dataSourceFactory.getUrl(),
dataSourceFactory.getUser(),
dataSourceFactory.getPassword());
}

@AfterAll
static void afterAll() throws SQLException {
shutdownH2Database(DATA_SOURCE);
shutdownH2Database(dataSource);

DATA_SOURCE = null;
dataSource = null;
}

@Override
protected SimpleSingleConnectionDataSource getDataSource() {
return DATA_SOURCE;
return dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@DisplayName("JdbcApplicationErrorDao (MySQL)")
class MySqlJdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTest {

private static SimpleSingleConnectionDataSource DATA_SOURCE;
private static SimpleSingleConnectionDataSource dataSource;

@Container
private static final MySQLContainer<?> MYSQL = newLatestMySQLContainer();
Expand All @@ -23,12 +23,12 @@ class MySqlJdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTe
static void beforeAll() {
migrateDatabase(MYSQL, "dropwizard-app-errors-migrations-mysql.xml");

DATA_SOURCE = new SimpleSingleConnectionDataSource(
dataSource = new SimpleSingleConnectionDataSource(
MYSQL.getJdbcUrl(), MYSQL.getUsername(), MYSQL.getPassword());
}

@Override
protected SimpleSingleConnectionDataSource getDataSource() {
return DATA_SOURCE;
return dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
@DisplayName("JdbcApplicationErrorDao (SQLite)")
class SqliteJdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTest {

private static SimpleSingleConnectionDataSource DATA_SOURCE;
private static SimpleSingleConnectionDataSource dataSource;

@BeforeAll
static void beforeAll() {
DATA_SOURCE = newInMemorySqliteDataSource();
migrateDatabase(DATA_SOURCE, "dropwizard-app-errors-migrations-sqlite.xml");
dataSource = newInMemorySqliteDataSource();
migrateDatabase(dataSource, "dropwizard-app-errors-migrations-sqlite.xml");
}

@Override
protected SimpleSingleConnectionDataSource getDataSource() {
return DATA_SOURCE;
return dataSource;
}
}

0 comments on commit ea265f4

Please sign in to comment.