BarcodeGeneratorProvider { public BarcodeGenerator getBarcodeGenerator(String id) throws BarcodeException { final Class<BarcodeGenerator> clazz = barcodeGenerators.get(id); if (clazz == null) { throw new BarcodeException("BarcodeGenerator with " + id + " is not available."); } BarcodeGenerator res = null; try { res = clazz.newInstance(); } catch (InstantiationException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { LOGGER.log(Level.SEVERE, null, ex); } return res; } private  BarcodeGeneratorProvider(); static synchronized BarcodeGeneratorProvider getInstance(); Collection<String> getAvailableBarcodeGenerators(); BarcodeGenerator getBarcodeGenerator(String id);  }
@Test public void getBarcodeGenerator() throws Exception { System.out.println("getBarcodeGenerator"); String id = "ean-13"; BarcodeGeneratorProvider instance = BarcodeGeneratorProvider.getInstance(); BarcodeGenerator result = instance.getBarcodeGenerator(id); assertNotNull(result); BarcodeGenerator result2 = instance.getBarcodeGenerator(id); assertNotSame("must be new instance", result2, result); }