### Question:
BootstrapConfigForGroup implements Function<String, BootstrapConfig> { @Override public BootstrapConfig apply(String from) { DatabagItem bootstrapConfig = api.getDatabagItem(databag, from); checkState(bootstrapConfig != null, "databag item %s/%s not found", databag, from); return json.fromJson(bootstrapConfig.toString(), BootstrapConfig.class); } @Inject  BootstrapConfigForGroup(@Named(CHEF_BOOTSTRAP_DATABAG) String databag, ChefApi api, Json json); @Override BootstrapConfig apply(String from);  }### Answer:
@Test(expectedExceptions = IllegalStateException.class) public void testWhenNoDatabagItem() throws IOException { ChefApi chefApi = createMock(ChefApi.class); Client client = createMock(Client.class); BootstrapConfigForGroup fn = new BootstrapConfigForGroup("jclouds", chefApi, json); expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(null); replay(client, chefApi); fn.apply("foo"); verify(client, chefApi); }
@Test public void testReturnsItem() throws IOException { ChefApi chefApi = createMock(ChefApi.class); Client client = createMock(Client.class); BootstrapConfigForGroup fn = new BootstrapConfigForGroup("jclouds", chefApi, json); DatabagItem databag = new DatabagItem("foo", "{\"environment\":\"development\",\"ssl_ca_file\":\"/etc/certs/chef-server.crt\"," + "\"ssl_verify_mode\": \":verify_peer\"," + "\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"]," + "\"attributes\":{\"tomcat6\":{\"ssl_port\":8433}}}"); expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(databag); replay(client, chefApi); BootstrapConfig config = fn.apply("foo"); assertEquals(config.getEnvironment(), "development"); assertEquals(config.getSslCAFile(), "/etc/certs/chef-server.crt"); assertEquals(config.getSslVerifyMode(), SSLVerifyMode.PEER); assertEquals(config.getRunList().get(0), "recipe[apache2]"); assertEquals(config.getRunList().get(1), "role[webserver]"); assertEquals(config.getAttributes().toString(), "{\"tomcat6\":{\"ssl_port\":8433}}"); verify(client, chefApi); }