### Question:
CouchDBDataStore implements DataStore { @Override public String updateVersion(final String endpointToken, final long version) throws VersionException, ChannelNotFoundException { final ViewResult viewResult = db.queryView(query(Views.TOKEN.viewName(), endpointToken)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { throw new ChannelNotFoundException("Cound not find channel for endpointToken", endpointToken); } final ObjectNode node = (ObjectNode) rows.get(0).getValueAsNode().get(DOC_FIELD); final long currentVersion = node.get(VERSION_FIELD).asLong(); if (version <= currentVersion) { throw new VersionException("version [" + version + "] must be greater than the current version [" + currentVersion + "]"); } node.put(VERSION_FIELD, String.valueOf(version)); db.update(node); return node.get(CHID_FIELD).asText(); } CouchDBDataStore(final String url, final String dbName); @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel channel); @Override Channel getChannel(final String channelId); @Override void removeChannels(final String uaid); @Override void removeChannels(final Set<String> channelIds); @Override Set<String> getChannelIds(final String uaid); @Override String updateVersion(final String endpointToken, final long version); @Override String saveUnacknowledged(final String channelId, final long version); @Override Set<Ack> getUnacknowledged(final String uaid); @Override Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked);  }### Answer:
@Test (expected = ChannelNotFoundException.class) public void updateVersionNonExistingEndpointToken() throws VersionException, ChannelNotFoundException { final Channel channel = newChannel(UUIDUtil.newUAID(), UUID.randomUUID().toString()); datastore.updateVersion(channel.getEndpointToken(), 2); }
@Test public void updateVersion() throws VersionException, ChannelNotFoundException { final Channel channel = newChannel(UUIDUtil.newUAID(), UUID.randomUUID().toString()); datastore.saveChannel(channel); final String channelId = datastore.updateVersion(channel.getEndpointToken(), 2); assertThat(channel.getChannelId(), is(equalTo(channelId))); }