Adds a couple of unit tests for the browser
This commit is contained in:
@@ -89,6 +89,9 @@ var listeners = [function (message, returnValue) {
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case "NumberPing":
|
||||
returnValue = message.number;
|
||||
break;
|
||||
case "CommandLoadSong":
|
||||
returnValue = () => {
|
||||
if (message.song)
|
||||
|
||||
@@ -60,7 +60,8 @@ dependencies {
|
||||
implementation 'org.apache.logging.log4j:log4j-core:2.13.3'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.3'
|
||||
implementation project(":browserCommands")
|
||||
addon project(path: ":add-on", configuration: 'addonBuild')
|
||||
testImplementation 'junit:junit:4.12'
|
||||
addon project(path: ":add-on", configuration: 'addonBuild')
|
||||
}
|
||||
|
||||
task downloadWindows_x86_64(type: Download) {
|
||||
|
||||
76
browser/src/test/java/PingTest.java
Normal file
76
browser/src/test/java/PingTest.java
Normal file
@@ -0,0 +1,76 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import edu.regis.universeplayer.NumberPing;
|
||||
import edu.regis.universeplayer.browser.Browser;
|
||||
import edu.regis.universeplayer.browserCommands.CommandReturn;
|
||||
|
||||
public class PingTest
|
||||
{
|
||||
@BeforeClass
|
||||
public static void setupBrowser() throws IOException, InterruptedException
|
||||
{
|
||||
System.out.println("Creating browser");
|
||||
Browser.createBrowser();
|
||||
System.out.println("Browser created");
|
||||
if (Browser.getInstance() == null)
|
||||
{
|
||||
Browser.waitInstance();
|
||||
}
|
||||
Thread thread = new Thread(Browser.getInstance());
|
||||
thread.start();
|
||||
System.out.println("Browser fully initialized");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeBrowser() throws IOException, InterruptedException
|
||||
{
|
||||
Browser.getInstance().stop();
|
||||
System.out.println("Browser closed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPing() throws IOException, InterruptedException, ExecutionException
|
||||
{
|
||||
ArrayList<Future<Object>> futures = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
futures.add(Browser.getInstance().sendObject("ping"));
|
||||
}
|
||||
System.out.println("Pings sent");
|
||||
for (int i = 0; i < futures.size(); i++)
|
||||
{
|
||||
assertEquals("pong",
|
||||
((CommandReturn<String>) futures.get(i).get())
|
||||
.getReturnValue());
|
||||
}
|
||||
System.out.println("Objects received");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumPing() throws IOException, InterruptedException,
|
||||
ExecutionException
|
||||
{
|
||||
ArrayList<Future<Object>> futures = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
futures.add(Browser.getInstance().sendObject(new NumberPing(i)));
|
||||
}
|
||||
System.out.println("Numbered pings sent");
|
||||
for (int i = 0; i < futures.size(); i++)
|
||||
{
|
||||
assertEquals(i,
|
||||
((CommandReturn<Double>) futures.get(i).get())
|
||||
.getReturnValue(), 0.001);
|
||||
}
|
||||
System.out.println("Objects received");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package edu.regis.universeplayer;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A test class for pinging the browser.
|
||||
*/
|
||||
public class NumberPing implements Serializable
|
||||
{
|
||||
public int number;
|
||||
|
||||
public NumberPing()
|
||||
{
|
||||
this(0);
|
||||
}
|
||||
|
||||
public NumberPing(int number)
|
||||
{
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user