### Question:
GroupToBootScript { public Statement apply(String group, @Nullable String nodeName) { BootstrapConfig config = null; try { config = bootstrapConfigForGroup.load(checkNotNull(group, "group")); } catch (Exception ex) { throw Throwables.propagate(ex); } String chefConfigDir = "{root}etc{fs}chef"; String chefBootFile = chefConfigDir + "{fs}first-boot.json"; ImmutableList.Builder<Statement> statements = ImmutableList.builder(); statements.add(new ExitInsteadOfReturn(installChef)); statements.add(exec("{md} " + chefConfigDir)); if (config.getSslCAFile() != null) { statements.add(createOrOverwriteFile(chefConfigDir + "{fs}chef-server.crt", Splitter.on(newLinePattern).split(config.getSslCAFile()))); } statements.add(createClientRbFile(chefConfigDir + "{fs}client.rb", group, nodeName, config)); statements.add(createOrOverwriteFile(chefConfigDir + "{fs}validation.pem", Splitter.on(newLinePattern).split(Pems.pem(validatorCredential.get())))); statements.add(createAttributesFile(chefBootFile, config)); statements.add(exec("chef-client -j " + chefBootFile)); return new StatementList(statements.build()); } @Inject  GroupToBootScript(@Provider Supplier<URI> endpoint, CacheLoader<String, BootstrapConfig> bootstrapConfigForGroup,
         @InstallChef Statement installChef, @Validator Optional<String> validatorName,
         @Validator Optional<PrivateKey> validatorCredential); Statement apply(String group, @Nullable String nodeName);  }### Answer:
@Test(expectedExceptions = IllegalStateException.class) public void testMustHaveValidatorName() { Optional<PrivateKey> validatorCredential = Optional.of(createMock(PrivateKey.class)); GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http: CacheLoader.from(Functions.forMap(ImmutableMap.of("foo", BootstrapConfig.builder().build()))), installChefOmnibus, Optional.<String> absent(), validatorCredential); fn.apply("foo", null); }
@Test(expectedExceptions = IllegalStateException.class) public void testMustHaveValidatorCredential() { GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http: CacheLoader.from(Functions.forMap(ImmutableMap.of("foo", BootstrapConfig.builder().build()))), installChefOmnibus, validatorName, Optional.<PrivateKey> absent()); fn.apply("foo", null); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Key 'foo' not present in map") public void testMustHaveRunScriptsName() { Optional<PrivateKey> validatorCredential = Optional.of(createMock(PrivateKey.class)); GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http: CacheLoader.from(Functions.forMap(ImmutableMap.<String, BootstrapConfig> of())), installChefOmnibus, validatorName, validatorCredential); fn.apply("foo", null); }
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "null value in entry: foo=null") public void testMustHaveRunScriptsValue() { Optional<PrivateKey> validatorCredential = Optional.of(createMock(PrivateKey.class)); GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http: CacheLoader.from(Functions.forMap(ImmutableMap.of("foo", (BootstrapConfig) null))), installChefOmnibus, validatorName, validatorCredential); fn.apply("foo", null); }