MongoTicketRepository implements LotteryTicketRepository { public int getNextId() { Document find = new Document("_id", "ticketId"); Document increase = new Document("seq", 1); Document update = new Document("$inc", increase); Document result = countersCollection.findOneAndUpdate(find, update); return result.getInteger("seq"); } MongoTicketRepository();  MongoTicketRepository(String dbName, String ticketsCollectionName,
                                 String countersCollectionName); void connect(); void connect(String dbName, String ticketsCollectionName,
                        String countersCollectionName); int getNextId(); MongoClient getMongoClient(); MongoDatabase getMongoDatabase(); MongoCollection<Document> getTicketsCollection(); MongoCollection<Document> getCountersCollection(); @Override Optional<LotteryTicket> findById(LotteryTicketId id); @Override Optional<LotteryTicketId> save(LotteryTicket ticket); @Override Map<LotteryTicketId, LotteryTicket> findAll(); @Override void deleteAll();  }
@Test public void testNextId() { assertEquals(1, repository.getNextId()); assertEquals(2, repository.getNextId()); assertEquals(3, repository.getNextId()); }