InstanceDomain(String name, int id, InstanceStoreFactory instanceStoreFactory) { this.name = name; this.id = id; this.instanceStore = instanceStoreFactory.createNewInstanceStore(name, this); }
@Test public void shouldReturnInstancesAssociatedWithTheStore() { InstanceStoreFactory instanceStoreFactory = mock(InstanceStoreFactory.class); Store<Instance> instanceStore = mock(Store.class); Collection<Instance> instances = singletonList(mock(Instance.class)); when(instanceStoreFactory.createNewInstanceStore(eq(DOMAIN), any(InstanceDomain.class))).thenReturn(instanceStore); when(instanceStore.all()).thenReturn(instances); InstanceDomain instanceDomain = new InstanceDomain(DOMAIN, 111, instanceStoreFactory); assertThat(instanceDomain.getInstances(), is(instances)); } }
@Test public void shouldCreateANewInstanceStoreV2() { IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); PcpStringStore stringStore = mock(PcpStringStore.class); InstanceDomain instanceDomain = mock(InstanceDomain.class); InstanceStoreFactory instanceStoreFactory = new InstanceStoreFactoryV2(identifierSourceSet, stringStore); Store<Instance> actual = instanceStoreFactory.createNewInstanceStore(STORE_NAME, instanceDomain); Store<Instance> expected = new InstanceV2.InstanceStoreV2(identifierSourceSet, STORE_NAME, instanceDomain, stringStore); assertReflectionEquals(expected, actual); }
@Test public void createNewInstanceStoreShouldReturnACorrectlyConstructedInstanceStore() { IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); InstanceDomain instanceDomain = mock(InstanceDomain.class); InstanceStoreFactory instanceStoreFactory = new InstanceStoreFactoryV1(identifierSourceSet); Store<Instance> actual = instanceStoreFactory.createNewInstanceStore(STORE_NAME, instanceDomain); Store<Instance> expected = new InstanceStoreV1(identifierSourceSet, STORE_NAME, instanceDomain); assertReflectionEquals(expected, actual); }