File tree Expand file tree Collapse file tree
app/src/test/java/org/gnucash/android/test/unit/db Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3636
3737import javax .xml .parsers .ParserConfigurationException ;
3838
39+ import static junit .framework .Assert .fail ;
3940import 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
You can’t perform that action at this time.
0 commit comments