ContextGeneratorRandom implements ContextGenerator { @Override public URI getUniqueContext(URI prefix) { BigInteger randomNumber = new BigInteger(SIZE_OF_RANDOM_NUMBER_IN_BITS, secureRandom); return URI.create(prefix + "/" + randomNumber.toString(Character.MAX_RADIX)); } ContextGeneratorRandom(); @Override URI getUniqueContext(URI prefix); @Override BigInteger getRandomNumber(long bits);  }
@Test public void testUniqueness() throws URISyntaxException { final int NUMBER_OF_CONTEXTS_TO_GENERATE = 100; final URI prefix = new URI("abc4trust.eu/test-context"); Set<URI> contexts = new HashSet<URI>(); for(int i=0;i<NUMBER_OF_CONTEXTS_TO_GENERATE;++i) { URI context = contextGenerator.getUniqueContext(prefix); contexts.add(context); } assertEquals(NUMBER_OF_CONTEXTS_TO_GENERATE, contexts.size()); }
@Test public void testPrefixPresent() throws URISyntaxException { final URI prefix = new URI("abc4trust.eu/test-context"); URI context = contextGenerator.getUniqueContext(prefix); assertTrue(context.toString().startsWith(prefix.toString())); }