Skip to content

Commit

Permalink
Various improvements related to Basename
Browse files Browse the repository at this point in the history
- derive file prefix from Basename enum name
- avoid hard-coded file names
- harmonize names of test databases
  • Loading branch information
spannm committed Mar 14, 2024
1 parent 7afc9d5 commit 84bdc29
Show file tree
Hide file tree
Showing 90 changed files with 126 additions and 89 deletions.
29 changes: 29 additions & 0 deletions src/main/java/io/github/spannm/jackcess/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,35 @@ public static String capitalize(String str) {
return cp == newCp ? str : (char) newCp + str.substring(1);
}

/**
* Converts a string to "title case", a type of capitalization in which the first letter of a word (following an underscore) except in position 0 is capitalized,
* underscores are removed, and the rest of the letters are lower-case.
*/
public static String toTitleCase(String str) {
if (str == null || str.isBlank()) {
return str;
}
StringBuilder sb = new StringBuilder();
boolean nextUpper = false;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if ('_' == c) {
nextUpper = true; // skip underscore, next char upper
} else if (i == 0) {
sb.append(Character.toLowerCase(c));
} else if (nextUpper) {
if ('_' != c) {
sb.append(Character.toTitleCase(c));
nextUpper = false;
} // else skip underscore, next char upper
} else {
sb.append(Character.toLowerCase(c));
}
}

return sb.toString();
}

public static String replace(String text, CharSequence searchString, CharSequence replacement) {
return isEmpty(text) || isEmpty(searchString) ? text : text.replace(searchString, replacement);
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/io/github/spannm/jackcess/ComplexColumnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.github.spannm.jackcess;

import static io.github.spannm.jackcess.test.Basename.COMPLEX;
import static io.github.spannm.jackcess.test.Basename.UNSUPPORTED;
import static io.github.spannm.jackcess.test.Basename.COMPLEX_DATA;
import static io.github.spannm.jackcess.test.Basename.UNSUPPORTED_FIELDS;
import static io.github.spannm.jackcess.test.TestUtil.TEST_TZ;
import static io.github.spannm.jackcess.test.TestUtil.assertSameDate;

Expand Down Expand Up @@ -60,7 +60,7 @@ class ComplexColumnTest extends AbstractBaseTest {
private static final byte[] TEST2_BYTES = getAsciiBytes("this is some more test data for attachment.");

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(COMPLEX)
@TestDbSource(COMPLEX_DATA)
void testVersions(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
db.setDateTimeType(DateTimeType.DATE);
Expand Down Expand Up @@ -146,7 +146,7 @@ void testVersions(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(COMPLEX)
@TestDbSource(COMPLEX_DATA)
void testAttachments(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
Table t1 = db.getTable("Table1");
Expand Down Expand Up @@ -224,7 +224,7 @@ void testAttachments(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(COMPLEX)
@TestDbSource(COMPLEX_DATA)
void testMultiValues(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
Table t1 = db.getTable("Table1");
Expand Down Expand Up @@ -294,7 +294,7 @@ void testMultiValues(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(UNSUPPORTED)
@TestDbSource(UNSUPPORTED_FIELDS)
void testUnsupported(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
Table t1 = db.getTable("Test");
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/io/github/spannm/jackcess/DatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void testReadDeletedRows(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testGetColumns(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
List<? extends Column> columns = db.getTable("Table1").getColumns();
Expand All @@ -138,7 +138,7 @@ private static void checkColumn(List<? extends Column> columns, int columnNumber
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testGetNextRow(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
db.setDateTimeType(DateTimeType.DATE);
Expand Down Expand Up @@ -465,7 +465,7 @@ void testFixedNumeric(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testMultiPageTableDef(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
List<? extends Column> columns = db.getTable("Table2").getColumns();
Expand Down Expand Up @@ -750,7 +750,7 @@ void testFixedText(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testDbSortOrder(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
assertEquals(((DatabaseImpl) db).getFormat().DEFAULT_SORT_ORDER,
Expand All @@ -759,7 +759,7 @@ void testDbSortOrder(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(UNSUPPORTED)
@TestDbSource(UNSUPPORTED_FIELDS)
void testUnsupportedColumns(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
Table t = db.getTable("Test");
Expand Down Expand Up @@ -851,7 +851,7 @@ void testToString() {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testIterateTableNames1(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
Set<String> names = new HashSet<>();
Expand Down Expand Up @@ -898,7 +898,7 @@ void testIterateTableNames2(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testTableDates(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
Table table = db.getTable("Table1");
Expand All @@ -917,7 +917,7 @@ void testTableDates(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testBrokenIndex(TestDb testDb) throws Exception {
try (Database db = new DatabaseBuilder(testDb.getFile())
.withReadOnly(true).withIgnoreBrokenSystemCatalogIndex(true).open()) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/github/spannm/jackcess/PropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.github.spannm.jackcess;

import static io.github.spannm.jackcess.test.Basename.TEST;
import static io.github.spannm.jackcess.test.Basename.COMMON1;

import io.github.spannm.jackcess.Database.FileFormat;
import io.github.spannm.jackcess.impl.DatabaseImpl;
Expand Down Expand Up @@ -119,7 +119,7 @@ void testInferTypes() {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testReadProperties(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
TableImpl t = (TableImpl) db.getTable("Table1");
Expand Down Expand Up @@ -202,7 +202,7 @@ void testParseProperties(FileFormat ff) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testWriteProperties(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
TableImpl t = (TableImpl) db.getTable("Table1");
Expand Down Expand Up @@ -232,7 +232,7 @@ void testWriteProperties(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testModifyProperties(TestDb testDb) throws Exception {
Database db = testDb.openCopy();
File dbFile = db.getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static io.github.spannm.jackcess.DatabaseBuilder.newColumn;
import static io.github.spannm.jackcess.DatabaseBuilder.newTable;
import static io.github.spannm.jackcess.test.Basename.COMPLEX;
import static io.github.spannm.jackcess.test.Basename.TEST;
import static io.github.spannm.jackcess.test.Basename.COMPLEX_DATA;
import static io.github.spannm.jackcess.test.Basename.COMMON1;
import static io.github.spannm.jackcess.test.TestUtil.*;

import io.github.spannm.jackcess.*;
Expand Down Expand Up @@ -57,7 +57,7 @@ void testAutoNumber(FileFormat fileFormat) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testAutoNumberPK(TestDb testDB) throws Exception {
try (Database db = testDB.openMem()) {
Table table = db.getTable("Table3");
Expand Down Expand Up @@ -247,7 +247,7 @@ private static void doTestInsertLongAutoNumber(Table table) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(COMPLEX)
@TestDbSource(COMPLEX_DATA)
void testInsertComplexAutoNumber(TestDb testDb) throws Exception {


Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/github/spannm/jackcess/impl/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void testByteCodeComparator() {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testPrimaryKey(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
Table table = db.getTable("Table1");
Expand Down Expand Up @@ -186,7 +186,7 @@ void testComplexIndex(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testEntryDeletion(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
Table table = db.getTable("Table1");
Expand Down Expand Up @@ -332,7 +332,7 @@ private void doTestUnique(Index index, int numValues, Object... testData) {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testUniqueEntryCount(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
db.setDateTimeType(DateTimeType.DATE);
Expand Down Expand Up @@ -390,7 +390,7 @@ void testUniqueEntryCount(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testReplId(TestDb testDb) throws Exception {
try (Database db = testDb.openCopy()) {
Table table = db.getTable("Table4");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.spannm.jackcess.impl;

import static io.github.spannm.jackcess.test.Basename.TEST;
import static io.github.spannm.jackcess.test.Basename.COMMON1;

import io.github.spannm.jackcess.DataType;
import io.github.spannm.jackcess.Database;
Expand Down Expand Up @@ -30,7 +30,7 @@ void testGetFormatNull() {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testGetFormat(TestDb testDb) throws Exception {
try (FileChannel channel = DatabaseImpl.openChannel(testDb.getFile().toPath(), false, false)) {

Expand All @@ -40,7 +40,7 @@ void testGetFormat(TestDb testDb) throws Exception {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testReadOnlyFormat(TestDb testDb) {
Exception failure = null;
try (Database db = testDb.openCopy()) {
Expand All @@ -62,7 +62,7 @@ void testReadOnlyFormat(TestDb testDb) {
}

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST)
@TestDbReadOnlySource(COMMON1)
void testFileFormat1(TestDb testDb) throws Exception {
try (Database db = testDb.open()) {
assertEquals(testDb.getExpectedFileFormat(), db.getFileFormat());
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/io/github/spannm/jackcess/impl/LongValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package io.github.spannm.jackcess.impl;

import static io.github.spannm.jackcess.test.Basename.TEST2;
import static io.github.spannm.jackcess.test.Basename.COMMON2;
import static io.github.spannm.jackcess.test.Basename.UNICODE_COMP;
import static io.github.spannm.jackcess.test.TestUtil.*;

import io.github.spannm.jackcess.*;
Expand All @@ -25,7 +26,6 @@
import io.github.spannm.jackcess.test.TestDb;
import io.github.spannm.jackcess.test.source.FileFormatSource;
import io.github.spannm.jackcess.test.source.TestDbReadOnlySource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

import java.io.File;
Expand All @@ -39,7 +39,7 @@
class LongValueTest extends AbstractBaseTest {

@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(TEST2)
@TestDbReadOnlySource(COMMON2)
void testReadLongValue(TestDb testDb) throws Exception {
try (Database db = testDb.openMem()) {
Table table = db.getTable("MSP_PROJECTS");
Expand Down Expand Up @@ -190,10 +190,10 @@ void testLongValueAsMiddleColumn(FileFormat fileFormat) throws Exception {
}
}

@Test
void testUnicodeCompression() throws Exception {
File dbFile = new File(DIR_TEST_DATA, "V2003/testUnicodeCompV2003.mdb");
try (Database db = open(FileFormat.V2003, dbFile, true)) {
@ParameterizedTest(name = "[{index}] {0}")
@TestDbReadOnlySource(UNICODE_COMP)
void testUnicodeCompression(TestDb testDb) throws Exception {
try (Database db = open(FileFormat.V2003, testDb.getFile(), true)) {
StringBuilder sb = new StringBuilder(127);
for (int i = 1; i <= 0xFF; i++) {
sb.append((char) i);
Expand Down
16 changes: 7 additions & 9 deletions src/test/java/io/github/spannm/jackcess/impl/UsageMapTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.spannm.jackcess.impl;

import static io.github.spannm.jackcess.test.Basename.TEST;
import static io.github.spannm.jackcess.test.Basename.COMMON1;
import static io.github.spannm.jackcess.test.Basename.REF_GLOBAL;
import static io.github.spannm.jackcess.test.TestUtil.createString;
import static io.github.spannm.jackcess.test.TestUtil.openCopy;

Expand All @@ -9,10 +10,8 @@
import io.github.spannm.jackcess.test.AbstractBaseTest;
import io.github.spannm.jackcess.test.TestDb;
import io.github.spannm.jackcess.test.source.TestDbSource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -22,7 +21,7 @@
public class UsageMapTest extends AbstractBaseTest {

@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(TEST)
@TestDbSource(COMMON1)
void testRead(TestDb testDB) throws Exception {
int expectedFirstPage;
int expectedLastPage;
Expand Down Expand Up @@ -52,11 +51,10 @@ void testRead(TestDb testDB) throws Exception {
}
}

@Test
void testGobalReferenceUsageMap() throws Exception {
try (Database db = openCopy(
FileFormat.V2000,
new File(DIR_TEST_DATA, "V2000/testRefGlobalV2000.mdb"))) {
@ParameterizedTest(name = "[{index}] {0}")
@TestDbSource(REF_GLOBAL)
void testGobalReferenceUsageMap(TestDb testDb) throws Exception {
try (Database db = openCopy(FileFormat.V2000, testDb.getFile())) {
Table t = new TableBuilder("Test2")
.addColumn(new ColumnBuilder("id", DataType.LONG))
.addColumn(new ColumnBuilder("data1", DataType.TEXT))
Expand Down
Loading

0 comments on commit 84bdc29

Please sign in to comment.