### Question:
MemoryCassandraInstanceDao implements CassandraInstanceDao { @Override public @Nullable CassandraInstance findById(String ring, int id) { CassandraInstance instance = null; if (rings.containsKey(ring)) { instance = rings.get(ring).get(id); } LOG.info("Returning instance: {}", instance); return instance; } MemoryCassandraInstanceDao(); @VisibleForTesting  MemoryCassandraInstanceDao(
      ConcurrentMap<String, Map<Integer, CassandraInstance>> rings); @Override ImmutableSet<CassandraInstance> findAll(String ring); @Override @Nullable CassandraInstance findById(String ring, int id); @Override void save(String ringName, CassandraInstance instance); @Override void delete(String ringName, CassandraInstance instance);  }### Answer:
@Test public void findById() { CassandraInstance instance = createMock(CassandraInstance.class); expect(rings.containsKey(RING_NAME)).andStubReturn(true); expect(rings.get(RING_NAME)).andStubReturn(ImmutableMap.of(CASSANDRA_ID, instance)); replayAll(); assertEquals(instance, dao.findById(RING_NAME, CASSANDRA_ID)); }
@Test public void findById_ringNotFound() { expect(rings.containsKey(RING_NAME)).andStubReturn(false); expect(rings.get(RING_NAME)).andStubReturn(null); replayAll(); assertNull(dao.findById(RING_NAME, CASSANDRA_ID)); }
@Test public void findById_instanceNotFound() { expect(rings.containsKey(RING_NAME)).andStubReturn(true); expect(rings.get(RING_NAME)).andStubReturn(ImmutableMap.<Integer, CassandraInstance>of()); replayAll(); assertNull(dao.findById(RING_NAME, CASSANDRA_ID)); }