### Question:
ServiceContext { public synchronized boolean addInstance(Instance instance) { if (instance == null) { return false; } String instanceServiceId = instance.getServiceId(); if (instanceServiceId == null || !serviceId.equals(instanceServiceId.toLowerCase())) { return false; } List<Instance> instances = service.getInstances(); if (instances == null) { instances = new ArrayList<>(); } deleteInstance(instance); instances.add(instance); service.setInstances(instances); return true; } ServiceContext(DiscoveryConfig discoveryConfig); DiscoveryConfig getDiscoveryConfig(); synchronized Service newService(); synchronized void setService(Service service); synchronized boolean deleteInstance(Instance instance); synchronized boolean updateInstance(Instance instance); synchronized boolean addInstance(Instance instance); synchronized boolean isAvailable(); synchronized Set<ServiceChangeListener> getListeners(); synchronized void addListener(final ServiceChangeListener listener); ServiceChangeEvent newServiceChangeEvent(final String changeType); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object other);  }### Answer:
@Test public void testAddInstance() { ServiceContext context = new ServiceContext(_discoveryConfig); Instance instance1 = Instances.newInstance(_serviceId); Assert.assertTrue(context.addInstance(instance1)); Assert.assertEquals(1, context.newService().getInstances().size()); Instance instance2 = instance1.clone(); instance2.setServiceId(instance1.getServiceId().toUpperCase()); Assert.assertTrue(context.addInstance(instance2)); Assert.assertEquals(1, context.newService().getInstances().size()); Assert.assertFalse(context.addInstance(Instances.newInstance())); Assert.assertEquals(1, context.newService().getInstances().size()); Assert.assertTrue(context.addInstance(Instances.newInstance(_serviceId))); Assert.assertEquals(2, context.newService().getInstances().size()); }