### Question:
PurchasingProcesses implements ConditionalSampler<Product, String> { public Product sample(String productCategory) throws Exception { return this.processes.get(productCategory).sample(); } PurchasingProcesses(Map<String, Sampler<Product>> processes); Product sample(String productCategory);  }### Answer:
@Test public void testSimulatePurchase() throws Exception { Map<Product, Double> productPDF = Maps.newHashMap(); for(int i = 0; i < 10; i++) { Map<String, Object> fields = Maps.newHashMap(); fields.put(Constants.PRODUCT_CATEGORY, "dog food"); fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1)); Product product = new Product(fields); productPDF.put(product, 0.1); } SeedFactory seedFactory = new SeedFactory(1234); Sampler<Product> sampler = RouletteWheelSampler.create(productPDF, seedFactory); Map<String, Sampler<Product>> processesMap = Maps.newHashMap(); processesMap.put("dog food", sampler); PurchasingProcesses processes = new PurchasingProcesses(processesMap); Product product = processes.sample("dog food"); assertNotNull(product); assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY)); assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY)); product = processes.sample("dog food"); assertNotNull(product); assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY)); assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY)); }