FixedValueIdentifierSource implements IdentifierSource { @Override public int calculateId(String name, Set<Integer> usedIds) { Integer reservedId = reservedIds.get(name); if (reservedId == null || usedIds.contains(reservedId)) { return fallback.calculateId(name, Sets.union(usedIds, new HashSet<Integer>(reservedIds .values()))); } return reservedId; } FixedValueIdentifierSource(Map<String, Integer> reservedIds, IdentifierSource fallback); @Override int calculateId(String name, Set<Integer> usedIds);  }
@Test public void shouldFallBackWhenNoValueProvided() { assertEquals(FIXED_FALLBACK, emptySource().calculateId(PREDEFINED_STRING, noExistingIdentifiers())); }
@Test public void shouldReturnFixedValueWhenProvided() { assertEquals(PREDEFINED_IDENTIFIER, populatedSource().calculateId(PREDEFINED_STRING, noExistingIdentifiers())); }
@Test public void shouldReturnFallBackWhenValueCollides() { assertEquals(FIXED_FALLBACK, populatedSource().calculateId(PREDEFINED_STRING, collidingIdentifiers())); }