Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 8dd6674

Browse files
author
Hideki Itakura
authored
Fixed #1691 - Database.getPath has return type as File which is different from other platforms (#1692)
1 parent ad4a554 commit 8dd6674

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/DatabaseTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ private Database openDatabase(String dbName, boolean countCheck) throws Couchbas
5757
config.setDirectory(getDir().getAbsolutePath());
5858
Database db = new Database(dbName, config);
5959
assertEquals(dbName, db.getName());
60-
assertTrue(db.getPath().getAbsolutePath().endsWith(".cblite2"));
60+
assertTrue(new File(db.getPath()).getAbsolutePath().endsWith(".cblite2"));
6161
if (countCheck)
6262
assertEquals(0, db.getCount());
6363
return db;
6464
}
6565

6666
// helper method to delete database
6767
void deleteDatabase(Database db) throws CouchbaseLiteException {
68-
File path = db.getPath();
68+
File path = db.getPath() != null ? new File(db.getPath()) : null;
6969
// if path is null, db is already closed
7070
if (path != null)
7171
assertTrue(path.exists());
@@ -193,7 +193,7 @@ public void testDatabaseConfigurationWithAndroidContect() throws CouchbaseLiteEx
193193
Database db = new Database("db", config);
194194
try {
195195
String expectedPath = context.getFilesDir().getAbsolutePath();
196-
assertTrue(db.getPath().getAbsolutePath().contains(expectedPath));
196+
assertTrue(new File(db.getPath()).getAbsolutePath().contains(expectedPath));
197197
} finally {
198198
db.delete();
199199
}
@@ -271,8 +271,8 @@ public void testCreateWithCustomDirectory() throws CouchbaseLiteException {
271271
try {
272272
assertNotNull(db);
273273
assertEquals(dbName, db.getName());
274-
assertTrue(db.getPath().getAbsolutePath().endsWith(".cblite2"));
275-
assertTrue(db.getPath().getAbsolutePath().indexOf(dir.getPath()) != -1);
274+
assertTrue(new File(db.getPath()).getAbsolutePath().endsWith(".cblite2"));
275+
assertTrue(new File(db.getPath()).getAbsolutePath().indexOf(dir.getPath()) != -1);
276276
assertTrue(Database.exists(dbName, dir));
277277
assertEquals(0, db.getCount());
278278
} finally {
@@ -941,7 +941,7 @@ public void testDelete() throws CouchbaseLiteException {
941941
@Test
942942
public void testDeleteTwice() throws CouchbaseLiteException {
943943
// delete db twice
944-
File path = db.getPath();
944+
File path = new File(db.getPath());
945945
assertTrue(path.exists());
946946
db.delete();
947947
try {
@@ -1051,7 +1051,7 @@ public void testDeleteWithDefaultDirDB() throws CouchbaseLiteException {
10511051
String dbName = "db";
10521052
try {
10531053
Database database = open(dbName);
1054-
File path = database.getPath();
1054+
File path = new File(database.getPath());
10551055
assertNotNull(path);
10561056
assertTrue(path.exists());
10571057
// close db before delete
@@ -1077,7 +1077,7 @@ public void testDeleteOpeningDBWithDefaultDir() throws CouchbaseLiteException {
10771077
// create db with custom directory
10781078
Database db = openDatabase(dbName);
10791079
try {
1080-
File path = db.getPath();
1080+
File path = new File(db.getPath());
10811081
assertNotNull(path);
10821082
assertTrue(path.exists());
10831083

@@ -1101,7 +1101,7 @@ public void testDeleteByStaticMethod() throws CouchbaseLiteException {
11011101

11021102
// create db with custom directory
11031103
Database db = openDatabase(dbName);
1104-
File path = db.getPath();
1104+
File path = new File(db.getPath());
11051105

11061106
// close db before delete
11071107
db.close();
@@ -1175,7 +1175,7 @@ public void testDatabaseExistsWithDir() throws CouchbaseLiteException {
11751175

11761176
// create db with custom directory
11771177
Database db = openDatabase("db");
1178-
File path = db.getPath();
1178+
File path = new File(db.getPath());
11791179

11801180
assertTrue(Database.exists("db", getDir()));
11811181

@@ -1322,7 +1322,7 @@ public void testCopy() throws CouchbaseLiteException {
13221322
Database.delete(dbName, dir);
13231323

13241324
// Copy:
1325-
Database.copy(db.getPath(), dbName, config);
1325+
Database.copy(new File(db.getPath()), dbName, config);
13261326

13271327
// Verify:
13281328
assertTrue(Database.exists(dbName, dir));

shared/src/main/java/com/couchbase/lite/AbstractDatabase.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public String getName() {
159159
*
160160
* @return the database's path.
161161
*/
162-
public File getPath() {
162+
public String getPath() {
163163
synchronized (lock) {
164-
return c4db != null ? new File(getC4Database().getPath()) : null;
164+
return c4db != null ? getC4Database().getPath() : null;
165165
}
166166
}
167167

@@ -660,8 +660,8 @@ Object getLock() {
660660

661661
boolean equalsWithPath(Database other) {
662662
if (other == null) return false;
663-
File path = getPath();
664-
File otherPath = other.getPath();
663+
File path = getFilePath();
664+
File otherPath = other.getFilePath();
665665
if (path == null && otherPath == null)
666666
return true;
667667
else if ((path == null && otherPath != null) || (path != null && otherPath == null))
@@ -779,6 +779,11 @@ ScheduledExecutorService getQueryExecutor() {
779779
return queryExecutor;
780780
}
781781

782+
File getFilePath() {
783+
String path = getPath();
784+
return path != null ? new File(path) : null;
785+
}
786+
782787
//---------------------------------------------
783788
// Private (in class only)
784789
//---------------------------------------------

0 commit comments

Comments
 (0)