Skip to content

Commit

Permalink
refactoring test code
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Sep 4, 2024
1 parent b5352d4 commit d7612ad
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/typewriter/postgres/PostgreSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class PostgreSQL extends Dialect {

static {
I.env("typewriter.connection.perThread.postgresql", true);

TYPES.put(int.class, "int");
TYPES.put(long.class, "bigint");
TYPES.put(float.class, "real");
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/typewriter/duck/DuckTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package typewriter.duck;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import kiss.Signal;
import typewriter.api.Identifiable;
Expand All @@ -20,10 +21,15 @@
public class DuckTestBase implements Testable {

/** The temporary database address. */
private final String db = "jdbc:duckdb::memory:test" + Testable.randomInt();
private String db;

@BeforeEach
void setup() {
db = "jdbc:duckdb::memory:test" + Testable.randomInt();
}

@AfterEach
void release() {
void cleanup() {
RDB.release(db);
}

Expand Down
10 changes: 8 additions & 2 deletions src/test/java/typewriter/h2/H2TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package typewriter.h2;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import kiss.Signal;
import typewriter.api.Identifiable;
Expand All @@ -20,10 +21,15 @@
public class H2TestBase implements Testable {

/** The temporary database address. */
private final String db = "jdbc:h2:mem:test" + Testable.randomInt();
private String db;

@BeforeEach
void setup() {
db = "jdbc:h2:mem:test" + Testable.randomInt();
}

@AfterEach
void release() {
void cleanup() {
RDB.release(db);
}

Expand Down
5 changes: 1 addition & 4 deletions src/test/java/typewriter/maria/MariaDBTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

import antibug.powerassert.PowerAssertOff;
import ch.vorburger.exec.ManagedProcessException;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
Expand All @@ -29,7 +28,6 @@
import typewriter.api.Testable;
import typewriter.rdb.RDB;

@PowerAssertOff
public class MariaDBTestBase implements Testable {

/** The invoked test manager. */
Expand All @@ -50,7 +48,7 @@ static synchronized void before() throws ManagedProcessException, InterruptedExc
dir = Locator.temporaryDirectory();

DBConfigurationBuilder builder = DBConfigurationBuilder.newBuilder()
.setPort(RandomUtils.nextInt(1024, 49151))
.setPort(RandomUtils.secure().randomInt(1024, 49151))
.setDataDir(dir.toString())
.setDeletingTemporaryBaseAndDataDirsOnShutdown(true);

Expand All @@ -76,7 +74,6 @@ void init() throws IOException, ManagedProcessException {
@AfterEach
void release() throws ManagedProcessException {
RDB.release(url);

}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/typewriter/sqlite/SQLiteTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package typewriter.sqlite;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import kiss.Signal;
import typewriter.api.Identifiable;
Expand All @@ -20,10 +21,15 @@
public class SQLiteTestBase implements Testable {

/** The temporary database address. */
private final String db = "jdbc:sqlite:file:memdb" + Testable.randomInt() + "?mode=memory&cache=shared";
private String db;

@BeforeEach
void setup() {
db = "jdbc:sqlite:file:memdb" + Testable.randomInt() + "?mode=memory&cache=shared";
}

@AfterEach
void release() {
void cleanup() {
RDB.release(db);
}

Expand Down

0 comments on commit d7612ad

Please sign in to comment.