@Override
    public long getMaxJournalId() {
        long ret = -1;
        if (bdbEnvironment == null) {
            return ret;
        }
        List<Long> dbNames = bdbEnvironment.getDatabaseNamesWithPrefix(prefix);
        if (dbNames == null || dbNames.isEmpty()) {
            return ret;
        }

        int index = dbNames.size() - 1;
        String dbName = getFullDatabaseName(dbNames.get(index));
        long dbNumberName = dbNames.get(index);
        // open database temporarily and close after count
        try (Database database = bdbEnvironment.openDatabase(dbName).getDb()) {
            ret = dbNumberName + database.count() - 1;
        }

        return ret;
    }
@Test
    public void testGetMaxJournalId(@Mocked CloseSafeDatabase closeSafeDatabase,
                                    @Mocked BDBEnvironment environment,
                                    @Mocked Database database) throws Exception {
        BDBJEJournal journal = new BDBJEJournal(environment);

        // failed to get database names; return -1
        new Expectations(environment) {
            {
                environment.getDatabaseNamesWithPrefix("");
                times = 1;
                result = null;
            }
        };
        Assert.assertEquals(-1, journal.getMaxJournalId());

        // no databases; return -1
        new Expectations(environment) {
            {
                environment.getDatabaseNamesWithPrefix("");
                times = 1;
                result = new ArrayList<>();
            }
        };
        Assert.assertEquals(-1, journal.getMaxJournalId());

        // db 3, 23, 45; open 45 get its size 10
        new Expectations(environment) {
            {
                environment.getDatabaseNamesWithPrefix("");
                times = 1;
                result = Arrays.asList(3L, 23L, 45L);

                environment.openDatabase("45");
                times = 1;
                result = closeSafeDatabase;
            }
        };
        new Expectations(closeSafeDatabase) {
            {
                closeSafeDatabase.getDb();
                times = 1;
                result = database;
            }
        };
        new Expectations(database) {
            {
                database.count();
                times = 1;
                result = 10;

                database.close();
                times = 1;
            }
        };
        Assert.assertEquals(54, journal.getMaxJournalId());
        journal.close();  // no db will closed
    }