HTMLParser { public long convertation(String time) { long result = 0L; if (time.contains("сегодня")) { time = time.replace("сегодня",""); result = System.currentTimeMillis(); } else if (time.contains("вчера")) { time = time.replace("вчера",""); result = System.currentTimeMillis() - 24 * 60 * 60 * 1000; } try { result = new SimpleDateFormat("dd MMM yy, HH:mm").parse(time).getTime(); } catch (ParseException e) { log.error(e.getMessage(),e); } return result; } HTMLParser(DBManager storage); Document getHtmlPage(String url); Elements getTableHtml(Document document); Elements getRowTable(Elements elements); boolean checkVacancy(String textVacancy); void addVacancy(String linkVacancy, String nameVacancy, String author, String linkAuthor, int ask, int view, long timeUpdate); long convertation(String time); String cleanNameVacancy(String name); long parseElementToVacancy(Elements column); long mainLoop();  }
@Test public void checkDataConvertationFromStringHtml() throws Exception { Properties properties = new Properties(); try (FileInputStream fileInputStream = new FileInputStream(this.getClass().getClassLoader().getResource("vacancy.properties").getPath())) { properties.load(fileInputStream); } catch (FileNotFoundException e) { } catch (IOException e) { } HTMLParser parser = new HTMLParser(new DBManager(properties)); long time = parser.convertation("сегодня"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); int year = 2016; Assert.assertThat(year,is(cal.get(1))); }
@Test public void checkDataYesterdayConvertationFromStringHtml() throws Exception { Properties properties = new Properties(); try (FileInputStream fileInputStream = new FileInputStream(this.getClass().getClassLoader().getResource("vacancy.properties").getPath())) { properties.load(fileInputStream); } catch (FileNotFoundException e) { } catch (IOException e) { } HTMLParser parser = new HTMLParser(new DBManager(properties)); long time = parser.convertation("вчера"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); int year = 2016; Assert.assertThat(year,is(cal.get(1))); }
@Test public void checkDataAnyConvertationFromStringHtml() throws Exception { Properties properties = new Properties(); try (FileInputStream fileInputStream = new FileInputStream(this.getClass().getClassLoader().getResource("vacancy.properties").getPath())) { properties.load(fileInputStream); } catch (FileNotFoundException e) { } catch (IOException e) { } HTMLParser parser = new HTMLParser(new DBManager(properties)); long time = parser.convertation("15 ноя 16, 13:47"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); int year = 2016; Assert.assertThat(year,is(cal.get(1))); }