Skip to content

Commit

Permalink
Upgrade from JUnit 4 to JUnit 5
Browse files Browse the repository at this point in the history
- Version upgrade from 4.13.2 to 5.10.2
- Introduce test base class AbstractBaseTest
- Parametrize several tests (that looped over several test databases)
- Move Basename, TestDB, TestUtil to new test package
- This increased test count from 201 to 652 (no actual increase of coverage)
- Add try-with-resources to countless test methods
- Test run-time using 'mvn test' (after mvn clean) unchanged
- Manage junit dependencies using org.junit:junit-bom ('bill of material')
  • Loading branch information
spannm committed Feb 21, 2024
1 parent 6e282b3 commit 8b5b13b
Show file tree
Hide file tree
Showing 52 changed files with 3,418 additions and 3,644 deletions.
41 changes: 33 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

<dep.slf4j.version>2.0.12</dep.slf4j.version>

<dep.junit.version>4.13.2</dep.junit.version>
<dep.junit.version>5.10.2</dep.junit.version>

<dep.plugin.sortpom.version>3.3.0</dep.plugin.sortpom.version>

Expand All @@ -114,6 +114,18 @@
<basepom.site.skip-deploy>false</basepom.site.skip-deploy>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${dep.junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
Expand All @@ -137,9 +149,26 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${dep.junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -164,13 +193,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables combine.children="append">
<user.timezone/>
</systemPropertyVariables>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
<argLine>@{basepom.coverage.test-args} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/spannm/jackcess/ColumnBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.spannm.jackcess;

import io.github.spannm.jackcess.Database.FileFormat;
import io.github.spannm.jackcess.impl.*;

import java.io.IOException;
Expand Down Expand Up @@ -100,8 +101,7 @@ public ColumnBuilder withSqlType(int type, int lengthInUnits)
* Sets the type for the new column based on the given SQL type, target data length (in type specific units), and
* target FileFormat.
*/
public ColumnBuilder withSqlType(int type, int lengthInUnits,
Database.FileFormat fileFormat)
public ColumnBuilder withSqlType(int type, int lengthInUnits, FileFormat fileFormat)
throws IOException {
return withType(DataType.fromSQLType(type, lengthInUnits, fileFormat));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/spannm/jackcess/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.spannm.jackcess;

import io.github.spannm.jackcess.Database.FileFormat;
import io.github.spannm.jackcess.impl.DatabaseImpl;
import io.github.spannm.jackcess.impl.JetFormat;
import io.github.spannm.jackcess.impl.SqlHelper;
Expand Down Expand Up @@ -444,7 +445,7 @@ public static DataType fromSQLType(int sqlType, int lengthInUnits) throws IOExce
return fromSQLType(sqlType, lengthInUnits, null);
}

public static DataType fromSQLType(int sqlType, int lengthInUnits, Database.FileFormat fileFormat)
public static DataType fromSQLType(int sqlType, int lengthInUnits, FileFormat fileFormat)
throws IOException {
DataType[] rtnArr = SQL_TYPES.get(sqlType);
if (rtnArr == null) {
Expand Down
133 changes: 58 additions & 75 deletions src/main/java/io/github/spannm/jackcess/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,115 +59,59 @@ public interface Database extends Iterable<Table>, Closeable, Flushable {
/**
* the default sort order for table columns.
*/
Table.ColumnOrder DEFAULT_COLUMN_ORDER =
Table.ColumnOrder.DATA;
Table.ColumnOrder DEFAULT_COLUMN_ORDER = Table.ColumnOrder.DATA;

/**
* system property which can be used to set the default TimeZone used for date calculations.
*/
String TIMEZONE_PROPERTY =
"jackcess.timeZone";
String TIMEZONE_PROPERTY = "jackcess.timeZone";

/**
* system property prefix which can be used to set the default Charset used for text data (full property includes
* the JetFormat version).
*/
String CHARSET_PROPERTY_PREFIX =
"jackcess.charset.";
String CHARSET_PROPERTY_PREFIX = "jackcess.charset.";

/**
* system property which can be used to set the path from which classpath resources are loaded (must end with a "/"
* if non-empty). Default value is {@value io.github.spannm.jackcess.impl.DatabaseImpl#DEFAULT_RESOURCE_PATH}
* if unspecified.
*/
String RESOURCE_PATH_PROPERTY =
"jackcess.resourcePath";
String RESOURCE_PATH_PROPERTY = "jackcess.resourcePath";

/**
* (boolean) system property which can be used to indicate that the current vm has a poor nio implementation
* (specifically for {@code FileChannel.transferFrom})
*/
String BROKEN_NIO_PROPERTY =
"jackcess.brokenNio";
String BROKEN_NIO_PROPERTY = "jackcess.brokenNio";

/**
* system property which can be used to set the default sort order for table columns. Value should be one of
* {@link Table.ColumnOrder} enum values.
*/
String COLUMN_ORDER_PROPERTY =
"jackcess.columnOrder";
String COLUMN_ORDER_PROPERTY = "jackcess.columnOrder";

/**
* system property which can be used to set the default enforcement of foreign-key relationships. Defaults to
* {@code true}.
*/
String FK_ENFORCE_PROPERTY =
"jackcess.enforceForeignKeys";
String FK_ENFORCE_PROPERTY = "jackcess.enforceForeignKeys";

/**
* system property which can be used to set the default allow auto number insert policy. Defaults to {@code false}.
*/
String ALLOW_AUTONUM_INSERT_PROPERTY =
"jackcess.allowAutoNumberInsert";
String ALLOW_AUTONUM_INSERT_PROPERTY = "jackcess.allowAutoNumberInsert";

/**
* system property which can be used to disable expression evaluation if necessary. Defaults to {@code true}.
*/
String ENABLE_EXPRESSION_EVALUATION_PROPERTY =
"jackcess.enableExpressionEvaluation";
String ENABLE_EXPRESSION_EVALUATION_PROPERTY = "jackcess.enableExpressionEvaluation";

/**
* system property which can be used to set the default date/Time type. Value should be one of {@link DateTimeType}
* enum values.
*/
String DATE_TIME_TYPE_PROPERTY =
"jackcess.dateTimeType";

/**
* Enum which indicates which version of Access created the database.
*
*/
enum FileFormat {

/** A database which was created by MS Access 97 */
V1997(".mdb"),
/**
* A database which was most likely created programmatically (e.g. using windows ADOX)
*/
GENERIC_JET4(".mdb"),
/** A database which was created by MS Access 2000 */
V2000(".mdb"),
/** A database which was created by MS Access 2002/2003 */
V2003(".mdb"),
/** A database which was created by MS Access 2007 */
V2007(".accdb"),
/** A database which was created by MS Access 2010+ */
V2010(".accdb"),
/** A database which was created by MS Access 2016+ */
V2016(".accdb"),
/** A database which was created by MS Access 2019+ (Office 365) */
V2019(".accdb"),
/** A database which was created by MS Money */
MSISAM(".mny");

private final String _ext;

FileFormat(String ext) {
_ext = ext;
}

/**
* @return the file extension used for database files with this format.
*/
public String getFileExtension() {
return _ext;
}

@Override
public String toString() {
return name() + " [" + DatabaseImpl.getFileFormatDetails(this).getFormat() + "]";
}
}
String DATE_TIME_TYPE_PROPERTY = "jackcess.dateTimeType";

/**
* Returns the File underlying this Database
Expand Down Expand Up @@ -225,8 +169,7 @@ default Stream<Table> stream() {
* @return a Stream using the {@link #newTableMetaDataIterable}
*/
default Stream<TableMetaData> newTableMetaDataStream() {
return StreamSupport.stream(
newTableMetaDataIterable().spliterator(), false);
return StreamSupport.stream(newTableMetaDataIterable().spliterator(), false);
}

/**
Expand All @@ -244,8 +187,7 @@ default Stream<TableMetaData> newTableMetaDataStream() {
/**
* Finds all the relationships in the database between the given tables.
*/
List<Relationship> getRelationships(Table table1, Table table2)
throws IOException;
List<Relationship> getRelationships(Table table1, Table table2) throws IOException;

/**
* Finds all the relationships in the database for the given table.
Expand All @@ -266,8 +208,7 @@ List<Relationship> getRelationships(Table table1, Table table2)
* Warning, this may load <i>all</i> the Tables (metadata, not data) in the database which could cause memory
* issues.
*/
List<Relationship> getSystemRelationships()
throws IOException;
List<Relationship> getSystemRelationships() throws IOException;

/**
* Finds all the queries in the database.
Expand Down Expand Up @@ -313,9 +254,7 @@ List<Relationship> getSystemRelationships()
* @param linkedDbName path to the linked database
* @param linkedTableName name of the table in the linked database
*/
void createLinkedTable(String name, String linkedDbName,
String linkedTableName)
throws IOException;
void createLinkedTable(String name, String linkedDbName, String linkedTableName) throws IOException;

/**
* Flushes any current changes to the database file (and any linked databases) to disk.
Expand Down Expand Up @@ -480,4 +419,48 @@ void createLinkedTable(String name, String linkedDbName,
* Sets the DateTimeType. If {@code null}, resets to the default value.
*/
void setDateTimeType(DateTimeType dateTimeType);

/**
* Enum which indicates which version of Access created the database.
*/
enum FileFormat {

/** A database which was created by MS Access 97 */
V1997(".mdb"),
/** A database which was most likely created programmatically (e.g. using windows ADOX) */
GENERIC_JET4(".mdb"),
/** A database which was created by MS Access 2000 */
V2000(".mdb"),
/** A database which was created by MS Access 2002/2003 */
V2003(".mdb"),
/** A database which was created by MS Access 2007 */
V2007(".accdb"),
/** A database which was created by MS Access 2010+ */
V2010(".accdb"),
/** A database which was created by MS Access 2016+ */
V2016(".accdb"),
/** A database which was created by MS Access 2019+ (Office 365) */
V2019(".accdb"),
/** A database which was created by MS Money */
MSISAM(".mny");

private final String ext;

FileFormat(String _ext) {
ext = _ext;
}

/**
* @return the file extension used for database files with this format.
*/
public String getFileExtension() {
return ext;
}

@Override
public String toString() {
return name() + " [" + DatabaseImpl.getFileFormatDetails(this).getFormat() + "]";
}
}

}
7 changes: 4 additions & 3 deletions src/main/java/io/github/spannm/jackcess/DatabaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.spannm.jackcess;

import io.github.spannm.jackcess.Database.FileFormat;
import io.github.spannm.jackcess.impl.CodecProvider;
import io.github.spannm.jackcess.impl.DatabaseImpl;
import io.github.spannm.jackcess.impl.PropertyMapImpl;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class DatabaseBuilder {
/** optional CodecProvider for handling encoded mdbs */
private CodecProvider _codecProvider;
/** FileFormat to use when creating a new mdb */
private Database.FileFormat _fileFormat;
private FileFormat _fileFormat;
/**
* optional pre-opened FileChannel, will _not_ be closed by Database close
*/
Expand Down Expand Up @@ -153,7 +154,7 @@ public DatabaseBuilder withCodecProvider(CodecProvider codecProvider) {
/**
* Sets the version of new database ({@link #create} only).
*/
public DatabaseBuilder withFileFormat(Database.FileFormat fileFormat) {
public DatabaseBuilder withFileFormat(FileFormat fileFormat) {
_fileFormat = fileFormat;
return this;
}
Expand Down Expand Up @@ -304,7 +305,7 @@ public static Database open(Path mdbFile) throws IOException {
*
* @see DatabaseBuilder for more flexible Database creation
*/
public static Database create(Database.FileFormat fileFormat, File mdbFile)
public static Database create(FileFormat fileFormat, File mdbFile)
throws IOException {
return new DatabaseBuilder(mdbFile).withFileFormat(fileFormat).create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class DatabaseImpl implements Database, DateTimeContext {
/**
* additional internal details about each FileFormat
*/
private static final Map<Database.FileFormat, FileFormatDetails> FILE_FORMAT_DETAILS = new EnumMap<>(Database.FileFormat.class);
private static final Map<FileFormat, FileFormatDetails> FILE_FORMAT_DETAILS = new EnumMap<>(FileFormat.class);

static {
addFileFormatDetails(FileFormat.V1997, null, JetFormat.VERSION_3);
Expand Down Expand Up @@ -2027,7 +2027,7 @@ public static DateTimeType getDefaultDateTimeType() {
/**
* Copies the given db InputStream to the given channel using the most efficient means possible.
*/
protected static void transferDbFrom(FileChannel channel, InputStream in) throws IOException {
public static void transferDbFrom(FileChannel channel, InputStream in) throws IOException {
ReadableByteChannel readChannel = Channels.newChannel(in);
if (!BROKEN_NIO) {
// sane implementation
Expand Down Expand Up @@ -2626,7 +2626,7 @@ private void purgeOldRefs() {
}

/**
* Internal details for each FileForrmat
* Internal details for each FileFormat
*/
public static final class FileFormatDetails {
private final String _emptyFile;
Expand Down
Loading

0 comments on commit 8b5b13b

Please sign in to comment.