Skip to content

Commit 6e3eec3

Browse files
committed
Add unit test for no active book issue
1 parent 3cf78f0 commit 6e3eec3

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

app/src/test/java/org/gnucash/android/test/unit/db/BooksDbAdapterTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import javax.xml.parsers.ParserConfigurationException;
3838

39+
import static junit.framework.Assert.fail;
3940
import static org.assertj.core.api.Assertions.assertThat;
4041

4142
/**
@@ -158,6 +159,26 @@ public void testGeneratedDisplayNames_shouldBeUnique(){
158159
assertThat(generatedName).isEqualTo("Book 4");
159160
}
160161

162+
@Test
163+
public void recoverFromNoActiveBookFound() {
164+
Book book1 = new Book(BaseModel.generateUID());
165+
book1.setActive(false);
166+
mBooksDbAdapter.addRecord(book1);
167+
168+
Book book2 = new Book(BaseModel.generateUID());
169+
book2.setActive(false);
170+
mBooksDbAdapter.addRecord(book2);
171+
172+
try {
173+
mBooksDbAdapter.getActiveBookUID();
174+
fail("There shouldn't be any active book.");
175+
} catch (BooksDbAdapter.NoActiveBookFoundException e) {
176+
mBooksDbAdapter.fixBooksDatabase();
177+
}
178+
179+
assertThat(mBooksDbAdapter.getActiveBookUID()).isEqualTo(book1.getUID());
180+
}
181+
161182
/**
162183
* Creates a new database with default accounts
163184
* @return The book UID for the new database

0 commit comments

Comments
 (0)