Newer
Older
KA-Visual / src / getUrlResultsTest.java
Jonathan Ström on 21 Feb 2017 1 KB Minor changes.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class getUrlResultsTest {
	public static void runAll() {
		printInfo("runOfflineTest", !getUrlResultsTest.runOfflineTest());
		printInfo("runOnlineTest", !getUrlResultsTest.runOnlineTest());
	}
	
	public static boolean runOnlineTest() {
		String correct = "EXEMPELSEXEMPLAREXEMPLENEXEMPLET";
		String result = "";
		
		for (String line : getUrlResults.getSearchResults("EXEMP???")) {
			result += line;
		}
		
		return (correct.equals(result));
	}
	
	public static boolean runOfflineTest() {
		String correct = "EXEMPELSEXEMPLAREXEMPLENEXEMPLET";
		String result = "";
		
		for (String line : getUrlResults.getWordsList(getUrlListFromFile(), "EXEMP???")) {
			result += line;
		}
		
		return (correct.equals(result));
	}
	
	private static List<String> getUrlListFromFile() {
		List<String> linesList = new ArrayList<String>();
		
		try(BufferedReader br = new BufferedReader(new FileReader("getUrlResultsTestContent"))) {
		    
			String line = br.readLine();
		    while (line != null) {
		    	linesList.add(line);
		        line = br.readLine();
		    }
		    
		} catch (IOException ioe) {}
		
		return linesList;
	}
	
	private static void printInfo(String testMethod) {
		System.out.println("GetUrlResultsTest->" + testMethod + "(): [OK] Test completed successfully!");
	}
	private static void printError(String testMethod) {
		System.err.println("GetUrlResultsTest->" + testMethod + "(): [ERROR] Test did not complete successfully!");
	}
	private static void printInfo(String testMethod, boolean error) {
		if (error)
			printError(testMethod);
		else
			printInfo(testMethod);
	}
}