BaseParser implements SubstitutionScheduleParser { static Set<String> handleClassRanges(String klasse, JSONObject data) throws JSONException { HashSet<String> classes = new HashSet<>(); classes.add(klasse); return handleClassRanges(classes, data); } BaseParser(SubstitutionScheduleData scheduleData, CookieProvider cookieProvider); static BaseParser getInstance(SubstitutionScheduleData data, @Nullable CookieProvider cookieProvider); @Override LocalDateTime getLastChange(); abstract SubstitutionSchedule getSubstitutionSchedule(); abstract List<String> getAllClasses(); @SuppressWarnings("SameReturnValue") abstract List<String> getAllTeachers(); Credential getCredential(); void setCredential(Credential credential); void setDebuggingDataHandler(DebuggingDataHandler handler); void setLocalSource(Path localSource); boolean isPersonal(); static final String PARAM_CLASS_REGEX; }
@Test public void testHandleClassRanges() throws JSONException { JSONObject data = new JSONObject(); JSONObject classRanges = new JSONObject(); classRanges.put(BaseParser.CLASS_RANGES_RANGE_FORMAT, "gc-c"); classRanges.put(BaseParser.CLASS_RANGES_SINGLE_FORMAT, "gc"); classRanges.put(BaseParser.CLASS_RANGES_CLASS_REGEX, "\\w"); classRanges.put(BaseParser.CLASS_RANGES_GRADE_REGEX, "\\d+"); data.put(BaseParser.PARAM_CLASS_RANGES, classRanges); assertEquals(new HashSet<>(Arrays.asList("10a", "10b", "10c", "10d")), BaseParser.handleClassRanges("10a-d", data)); assertEquals(new HashSet<>(Collections.singletonList("10a")), BaseParser.handleClassRanges("10a", data)); classRanges.put(BaseParser.CLASS_RANGES_RANGE_FORMAT, "gc-gc"); assertEquals(new HashSet<>(Arrays.asList("10a", "10b", "10c", "10d")), BaseParser.handleClassRanges("10a-10d", data)); classRanges.put(BaseParser.CLASS_RANGES_CLASS_REGEX, "\\d"); classRanges.put(BaseParser.CLASS_RANGES_RANGE_FORMAT, "g/c-g/c"); classRanges.put(BaseParser.CLASS_RANGES_SINGLE_FORMAT, "g/c"); assertEquals(new HashSet<>(Arrays.asList("10/1", "10/2", "10/3", "10/4")), BaseParser.handleClassRanges("10/1-10/4", data)); }