@Test public void testCheckBoxParsing() throws CaptchaNoJsHtmlParser.CaptchaNoJsV2ParsingError { for (int i = 0; i < inputDataList.size(); ++i) { String inputData = inputDataList.get(i); CaptchaInfo captchaInfo = new CaptchaInfo(); parser.parseCheckboxes(inputData, captchaInfo); for (int j = 0; j < captchaInfo.checkboxes.size(); j++) { Integer checkbox = captchaInfo.checkboxes.get(j); assertEquals(checkbox, resultCheckboxList.get(i).get(j)); } } }
public void parseCheckboxes( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = checkboxesPattern.matcher(responseHtml); Set<Integer> checkboxesSet = new HashSet<>(matcher.groupCount()); int index = 0; while (matcher.find()) { try { Integer checkboxId = Integer.parseInt(matcher.group(1)); checkboxesSet.add(checkboxId); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error); } ++index; } if (checkboxesSet.isEmpty()) { throw new CaptchaNoJsV2ParsingError("Could not parse any checkboxes!"); } CaptchaInfo.CaptchaType captchaType; try { captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error); } if (captchaType == CaptchaInfo.CaptchaType.Unknown) { throw new CaptchaNoJsV2ParsingError("Unknown captcha type"); } captchaInfo.setCaptchaType(captchaType); captchaInfo.setCheckboxes(new ArrayList<>(checkboxesSet)); }
CaptchaNoJsHtmlParser { public void parseCheckboxes( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = checkboxesPattern.matcher(responseHtml); Set<Integer> checkboxesSet = new HashSet<>(matcher.groupCount()); int index = 0; while (matcher.find()) { try { Integer checkboxId = Integer.parseInt(matcher.group(1)); checkboxesSet.add(checkboxId); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error); } ++index; } if (checkboxesSet.isEmpty()) { throw new CaptchaNoJsV2ParsingError("Could not parse any checkboxes!"); } CaptchaInfo.CaptchaType captchaType; try { captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error); } if (captchaType == CaptchaInfo.CaptchaType.Unknown) { throw new CaptchaNoJsV2ParsingError("Unknown captcha type"); } captchaInfo.setCaptchaType(captchaType); captchaInfo.setCheckboxes(new ArrayList<>(checkboxesSet)); } }
CaptchaNoJsHtmlParser { public void parseCheckboxes( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = checkboxesPattern.matcher(responseHtml); Set<Integer> checkboxesSet = new HashSet<>(matcher.groupCount()); int index = 0; while (matcher.find()) { try { Integer checkboxId = Integer.parseInt(matcher.group(1)); checkboxesSet.add(checkboxId); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error); } ++index; } if (checkboxesSet.isEmpty()) { throw new CaptchaNoJsV2ParsingError("Could not parse any checkboxes!"); } CaptchaInfo.CaptchaType captchaType; try { captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error); } if (captchaType == CaptchaInfo.CaptchaType.Unknown) { throw new CaptchaNoJsV2ParsingError("Unknown captcha type"); } captchaInfo.setCaptchaType(captchaType); captchaInfo.setCheckboxes(new ArrayList<>(checkboxesSet)); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); }
CaptchaNoJsHtmlParser { public void parseCheckboxes( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = checkboxesPattern.matcher(responseHtml); Set<Integer> checkboxesSet = new HashSet<>(matcher.groupCount()); int index = 0; while (matcher.find()) { try { Integer checkboxId = Integer.parseInt(matcher.group(1)); checkboxesSet.add(checkboxId); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error); } ++index; } if (checkboxesSet.isEmpty()) { throw new CaptchaNoJsV2ParsingError("Could not parse any checkboxes!"); } CaptchaInfo.CaptchaType captchaType; try { captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error); } if (captchaType == CaptchaInfo.CaptchaType.Unknown) { throw new CaptchaNoJsV2ParsingError("Unknown captcha type"); } captchaInfo.setCaptchaType(captchaType); captchaInfo.setCheckboxes(new ArrayList<>(checkboxesSet)); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); @NonNull CaptchaInfo parseHtml(String responseHtml, String siteKey); void parseChallengeTitle(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCParameter(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCheckboxes(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); }
CaptchaNoJsHtmlParser { public void parseCheckboxes( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = checkboxesPattern.matcher(responseHtml); Set<Integer> checkboxesSet = new HashSet<>(matcher.groupCount()); int index = 0; while (matcher.find()) { try { Integer checkboxId = Integer.parseInt(matcher.group(1)); checkboxesSet.add(checkboxId); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error); } ++index; } if (checkboxesSet.isEmpty()) { throw new CaptchaNoJsV2ParsingError("Could not parse any checkboxes!"); } CaptchaInfo.CaptchaType captchaType; try { captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error); } if (captchaType == CaptchaInfo.CaptchaType.Unknown) { throw new CaptchaNoJsV2ParsingError("Unknown captcha type"); } captchaInfo.setCaptchaType(captchaType); captchaInfo.setCheckboxes(new ArrayList<>(checkboxesSet)); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); @NonNull CaptchaInfo parseHtml(String responseHtml, String siteKey); void parseChallengeTitle(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCParameter(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCheckboxes(
            String responseHtml,
            CaptchaInfo captchaInfo
    );  }