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

Commit a08c08b

Browse files
author
Hideki Itakura
committed
update unit test code
1 parent ea42c8c commit a08c08b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/androidTest/java/com/couchbase/lite/DocumentTest.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public void disabledTestNonsensicalConflictExceptionOnUnsavedRevision() throws C
458458
testNonsensicalConflict.setMap(new Mapper() {
459459
@Override
460460
public void map(Map<String, Object> document, Emitter emitter) {
461-
emitter.emit(null,null);
461+
emitter.emit(null, null);
462462
}
463463
}, "");
464464
Query query = testNonsensicalConflict.createQuery();
@@ -468,7 +468,7 @@ public void map(Map<String, Object> document, Emitter emitter) {
468468
@Override
469469
public void changed(LiveQuery.ChangeEvent event) {
470470
QueryEnumerator rows = event.getRows();
471-
while(rows.hasNext()){
471+
while (rows.hasNext()) {
472472
QueryRow next = rows.next();
473473
next.getDocument();
474474
}
@@ -531,7 +531,7 @@ public void changed(Document.ChangeEvent event) {
531531
/**
532532
* https://github.com/couchbase/couchbase-lite-android/issues/563
533533
* Updating a document in a transaction block twice using Document.DocumentUpdater results in an infinite loop
534-
*
534+
* <p/>
535535
* NOTE: Use Document.update()
536536
*/
537537
public void testMultipleUpdatesInTransactionWithUpdate() throws CouchbaseLiteException {
@@ -548,7 +548,7 @@ public boolean run() {
548548
doc.update(new Document.DocumentUpdater() {
549549
@Override
550550
public boolean update(UnsavedRevision newRevision) {
551-
Log.e("updateDocumentInTransactionTest", "Trying to update key to value 2");
551+
Log.e(TAG, "Trying to update key to value 2");
552552
Map<String, Object> properties = newRevision.getUserProperties();
553553
properties.put("key", "value2");
554554
newRevision.setUserProperties(properties);
@@ -558,15 +558,16 @@ public boolean update(UnsavedRevision newRevision) {
558558
doc.update(new Document.DocumentUpdater() {
559559
@Override
560560
public boolean update(UnsavedRevision newRevision) {
561-
Log.e("updateDocumentInTransactionTest", "Trying to update key to value 3");
561+
Log.e(TAG, "Trying to update key to value 3");
562562
Map<String, Object> properties = newRevision.getUserProperties();
563563
properties.put("key", "value3");
564564
newRevision.setUserProperties(properties);
565565
return true;
566566
}
567567
});
568568
} catch (CouchbaseLiteException e) {
569-
Log.e("updateDocumentInTransactionTest", "Trying to update key to value 2");
569+
Log.e(TAG, "Trying to update key to value 2 or 3");
570+
fail("Trying to update key to value 2 or 3, but failed.");
570571
return false;
571572
}
572573
return true;
@@ -578,7 +579,7 @@ public boolean update(UnsavedRevision newRevision) {
578579
}
579580

580581
/**
581-
* Note: Document.putProperties()
582+
* NOTE: This is variation of testMultipleUpdatesInTransactionWithUpdate() test with using Document.putProperties()
582583
*/
583584
public void testMultipleUpdatesInTransactionWithPutProperties() throws CouchbaseLiteException {
584585
Log.e(TAG, "testMultipleUpdatesInTransactionWithPutProperties() START");
@@ -594,18 +595,26 @@ public boolean run() {
594595
Map<String, Object> properties2 = new HashMap<String, Object>(doc.getProperties());
595596
properties2.put("key", "value2");
596597
doc.putProperties(properties2);
598+
} catch (CouchbaseLiteException e) {
599+
Log.e(TAG, "Trying to update key to value 2");
600+
fail("Trying to update key to value 2, but failed.");
601+
return false;
602+
}
603+
try {
597604
Map<String, Object> properties3 = new HashMap<String, Object>(doc.getProperties());
598605
properties3.put("key", "value3");
599606
doc.putProperties(properties3);
600607
} catch (CouchbaseLiteException e) {
601-
Log.e("updateDocumentInTransactionTest", "Trying to update key to value 2");
608+
Log.e(TAG, "Trying to update key to value 3");
609+
fail("Trying to update key to value 3, but failed.");
602610
return false;
603611
}
604612
return true;
605613
}
606614
});
607615
Map<String, Object> properties4 = doc.getProperties();
608-
Log.e(TAG, "properties4 = "+properties4);
616+
Log.e(TAG, "properties4 = " + properties4);
617+
assertEquals("value3", properties4.get("key"));
609618
Log.e(TAG, "testMultipleUpdatesInTransactionWithPutProperties() END");
610619
}
611620
}

0 commit comments

Comments
 (0)