Skip to content

Commit 63567fb

Browse files
BoxStoreBuilderTest: test directory path with unicode chars.
1 parent 4bda9ec commit 63567fb

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreBuilderTest.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@
2222
import org.junit.Before;
2323
import org.junit.Test;
2424

25-
2625
import java.io.File;
2726
import java.io.FileOutputStream;
2827
import java.io.IOException;
2928
import java.io.InputStream;
30-
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.util.Collections;
32+
import java.util.HashSet;
33+
import java.util.List;
34+
import java.util.Set;
35+
import java.util.stream.Collectors;
36+
import java.util.stream.Stream;
37+
38+
import static org.junit.Assert.assertEquals;
39+
import static org.junit.Assert.assertNotNull;
3140
import static org.junit.Assert.assertSame;
3241
import static org.junit.Assert.assertTrue;
3342
import static org.junit.Assert.fail;
34-
import static org.junit.Assert.assertNotNull;
3543

3644
public class BoxStoreBuilderTest extends AbstractObjectBoxTest {
3745

@@ -84,6 +92,34 @@ public void testDefaultStoreNull() {
8492
BoxStore.getDefault();
8593
}
8694

95+
@Test
96+
public void directoryUnicodePath() throws IOException {
97+
File parentTestDir = new File("unicode-test");
98+
File testDir = new File(parentTestDir, "Îñţérñåţîöñåļîžåţîờñ");
99+
builder.directory(testDir);
100+
BoxStore store = builder.build();
101+
store.close();
102+
103+
// Check only expected files and directories exist.
104+
Set<Path> expectedPaths = new HashSet<>();
105+
expectedPaths.add(parentTestDir.toPath());
106+
expectedPaths.add(testDir.toPath());
107+
Path testDirPath = testDir.toPath();
108+
expectedPaths.add(testDirPath.resolve("data.mdb"));
109+
expectedPaths.add(testDirPath.resolve("lock.mdb"));
110+
try (Stream<Path> files = Files.walk(parentTestDir.toPath())) {
111+
List<Path> unexpectedPaths = files.filter(path -> !expectedPaths.remove(path)).collect(Collectors.toList());
112+
if (!unexpectedPaths.isEmpty()) {
113+
fail("Found unexpected paths: " + unexpectedPaths);
114+
}
115+
if (!expectedPaths.isEmpty()) {
116+
fail("Missing expected paths: " + expectedPaths);
117+
}
118+
}
119+
120+
deleteAllFiles(parentTestDir);
121+
}
122+
87123
@Test
88124
public void testMaxReaders() {
89125
builder = createBoxStoreBuilder(null);

0 commit comments

Comments
 (0)