Skip to content

Commit

Permalink
Refactoring: change names of classes & packages, remove extra class
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-punko committed Nov 3, 2024
1 parent c466d44 commit 0fdb318
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 67 deletions.
2 changes: 1 addition & 1 deletion pravtor.ru-crawler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</descriptorRefs>
<archive>
<manifest>
<mainClass>by.andd3dfx.pravtor.SearchApp</mainClass>
<mainClass>by.andd3dfx.pravtor.MainApp</mainClass>
</manifest>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package by.andd3dfx.pravtor;

import by.andd3dfx.pravtor.model.BatchSearchResult;
import by.andd3dfx.pravtor.model.TorrentData;
import by.andd3dfx.pravtor.dto.BatchSearchResult;
import by.andd3dfx.pravtor.dto.TorrentData;
import by.andd3dfx.pravtor.util.FileUtil;
import by.andd3dfx.pravtor.util.SearchUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;

public class SearchApp {
public class MainApp {

public static void main(String[] args) throws IOException, InterruptedException {
public static void main(String[] args) throws IOException {
if (args.length != 2) {
throw new IllegalArgumentException("Should be 2 parameters!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.pravtor.model;
package by.andd3dfx.pravtor.dto;

import java.util.List;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.pravtor.model;
package by.andd3dfx.pravtor.dto;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.pravtor.model;
package by.andd3dfx.pravtor.dto;

import by.andd3dfx.crawler.dto.CrawlerData;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package by.andd3dfx.pravtor.util;

import by.andd3dfx.pravtor.model.BatchSearchResult;
import by.andd3dfx.pravtor.model.SearchCriteria;
import by.andd3dfx.pravtor.model.TorrentData;
import by.andd3dfx.pravtor.dto.BatchSearchResult;
import by.andd3dfx.pravtor.dto.SearchCriteria;
import by.andd3dfx.pravtor.dto.TorrentData;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

public class FileUtil {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package by.andd3dfx.pravtor.util;

import by.andd3dfx.crawler.engine.WebCrawler;
import by.andd3dfx.pravtor.model.TorrentData;
import by.andd3dfx.pravtor.dto.TorrentData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class SearchAppTest {
public class MainAppTest {

private final String PARAMS_FILE = "src/test/resources/test-params.txt";
private final String RESULT_XLS_FILE = "target/tmp-result.xls";

private SearchApp searchApp;
private MainApp mainApp;

@Before
public void setup() {
searchApp = new SearchApp();
mainApp = new MainApp();
}

@Test
public void testMain() throws IOException, InterruptedException {
searchApp.main(new String[]{PARAMS_FILE, RESULT_XLS_FILE});
public void testMain() throws IOException {
mainApp.main(new String[]{PARAMS_FILE, RESULT_XLS_FILE});

// Check output XLS existence
assertTrue(Files.exists(Path.of(RESULT_XLS_FILE)));
Expand Down Expand Up @@ -71,7 +71,7 @@ public void testMainWithThreeParamsProvided() throws Exception {

private void runMainNCheckExceptionThrow(String[] args) throws Exception {
try {
searchApp.main(args);
mainApp.main(args);
fail("Exception should be thrown");
} catch (IllegalArgumentException iae) {
assertThat(iae.getMessage(), is("Should be 2 parameters!"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package by.andd3dfx.pravtor.util;

import by.andd3dfx.pravtor.model.BatchSearchResult;
import by.andd3dfx.pravtor.model.SearchCriteria;
import by.andd3dfx.pravtor.model.TorrentData;
import by.andd3dfx.pravtor.dto.BatchSearchResult;
import by.andd3dfx.pravtor.dto.SearchCriteria;
import by.andd3dfx.pravtor.dto.TorrentData;
import org.dbunit.dataset.excel.XlsDataSet;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package by.andd3dfx.pravtor.util;

import by.andd3dfx.pravtor.model.TorrentData;
import by.andd3dfx.pravtor.dto.TorrentData;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package by.andd3dfx.sitesparsing.rabotaby;
package by.andd3dfx.rabotaby;

import by.andd3dfx.rabotaby.util.SearchUtil;
import by.andd3dfx.rabotaby.util.StatisticsUtil;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -16,7 +19,7 @@ public static void main(String[] args) throws IOException {
var pageUrl = searchUtil.buildSearchUrl("java");
var searchResult = searchUtil.batchSearch(pageUrl);

var statisticsSortedMap = new Statistics().collectStatistics(searchResult);
var statisticsSortedMap = new StatisticsUtil().collectStatistics(searchResult);

Path path = Paths.get(args[0]);
byte[] strToBytes = statisticsSortedMap.toString().getBytes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.sitesparsing.rabotaby.dto;
package by.andd3dfx.rabotaby.dto;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package by.andd3dfx.sitesparsing.rabotaby;
package by.andd3dfx.rabotaby.util;

import by.andd3dfx.crawler.engine.WebCrawler;
import by.andd3dfx.sitesparsing.rabotaby.dto.VacancyData;
import by.andd3dfx.rabotaby.dto.VacancyData;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package by.andd3dfx.sitesparsing.rabotaby;
package by.andd3dfx.rabotaby.util;

import by.andd3dfx.sitesparsing.rabotaby.dto.VacancyData;
import by.andd3dfx.rabotaby.dto.VacancyData;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -10,7 +10,7 @@

import static java.util.stream.Collectors.toMap;

public class Statistics {
public class StatisticsUtil {

private Map<String, Integer> keywordToFreqMap = new HashMap<>();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.sitesparsing.rabotaby;
package by.andd3dfx.rabotaby.util;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -11,12 +11,12 @@ public class SearchUtilTest {

private static final int RECORDS_PER_PAGE = 20;
private SearchUtil searchUtil;
private Statistics statistics;
private StatisticsUtil statisticsUtil;

@Before
public void setup() {
searchUtil = new SearchUtil();
statistics = new Statistics();
statisticsUtil = new StatisticsUtil();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.andd3dfx.sitesparsing.rabotaby;
package by.andd3dfx.rabotaby.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -8,33 +8,34 @@
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

public class StatisticsTest {
public class StatisticsUtilTest {

private Statistics statistics;
private StatisticsUtil statisticsUtil;

@Before
public void setUp() {
statistics = new Statistics();
statisticsUtil = new StatisticsUtil();
}

@Test
public void testStatisticsCollector() {
statistics.putKeyword("Java");
statistics.putKeyword("Spring");
statistics.putKeyword("Java");
statistics.putKeyword("Spring");
statistics.putKeyword("SQL");
statistics.putKeyword("Spring");

assertThat("Wrong amount of Java items", statistics.get("Java"), is(2));
assertThat("Wrong amount of SQL items", statistics.get("SQL"), is(1));
assertThat("Wrong amount of Spring items", statistics.get("Spring"), is(3));
assertThat("Wrong amount of absent item", statistics.get("EJB"), is(nullValue()));

final LinkedHashMap<String, Integer> map = statistics.buildSortedMap();
statisticsUtil.putKeyword("Java");
statisticsUtil.putKeyword("Spring");
statisticsUtil.putKeyword("Java");
statisticsUtil.putKeyword("Spring");
statisticsUtil.putKeyword("SQL");
statisticsUtil.putKeyword("Spring");

assertThat("Wrong amount of Java items", statisticsUtil.get("Java"), is(2));
assertThat("Wrong amount of SQL items", statisticsUtil.get("SQL"), is(1));
assertThat("Wrong amount of Spring items", statisticsUtil.get("Spring"), is(3));
assertThat("Wrong amount of absent item", statisticsUtil.get("EJB"), is(nullValue()));

final LinkedHashMap<String, Integer> map = statisticsUtil.buildSortedMap();
final Set<Entry<String, Integer>> entries = map.entrySet();
final Iterator<Entry<String, Integer>> iterator = entries.iterator();

Expand Down

0 comments on commit 0fdb318

Please sign in to comment.