### Question:
PatternGenerator { @Nonnull public static String acceptStrings(@Nonnull String[] input) { StringBuilder builder = new StringBuilder(); builder.append("("); for (int i = 0; i < input.length; i++) { builder.append(Pattern.quote(input[i])); if (i < input.length - 1) { builder.append("|"); } } builder.append(")"); return builder.toString(); }  @Nonnull static String acceptStrings(@Nonnull String[] input);  }### Answer:
@Test public void testAcceptStrings() { String[] input = new String[3]; input[0] = "foo"; input[1] = "bar"; input[2] = "baz"; String regex = PatternGenerator.acceptStrings(input); Pattern pattern = Pattern.compile(regex); assertTrue(pattern.matcher("foo").matches()); assertTrue(pattern.matcher("bar").matches()); assertTrue(pattern.matcher("baz").matches()); assertFalse(pattern.matcher("foobaz").matches()); assertFalse(pattern.matcher("").matches()); }
@Test public void testSubsequence() { String[] input = new String[3]; input[0] = "foo"; input[1] = "bar"; input[2] = "baz"; String regex = PatternGenerator.acceptStrings(input); Pattern pattern = Pattern.compile(regex); assertTrue(pattern.matcher("foo").find()); assertTrue(pattern.matcher("bar").find()); assertTrue(pattern.matcher("baz").find()); assertTrue(pattern.matcher("hellofoo").find()); assertTrue(pattern.matcher("hellofooworld").find()); assertFalse(pattern.matcher("").find()); }