Fixed broken tests

This commit is contained in:
Rsl1122 2020-01-07 17:33:05 +02:00
parent 9480245dae
commit a5219dd901
4 changed files with 50 additions and 5 deletions

View File

@ -107,7 +107,7 @@ class JSErrorRegressionTest {
}
private void assertNo500Error(WebDriver driver) {
assertFalse(driver.getPageSource().contains("500 Internal Error occurred"), driver.getPageSource());
assertFalse(driver.getPageSource().contains("<span class=\"loader-text\">Error occurred"), driver.getPageSource());
}
@Test

View File

@ -31,6 +31,7 @@ import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import utilities.mocks.objects.TestRunnableFactory;
import java.io.File;
import java.io.IOException;
@ -91,7 +92,7 @@ class GeolocationTest {
assertTrue(config.isTrue(DataGatheringSettings.GEOLOCATIONS));
GeoLite2Geolocator geoLite2Geolocator = new GeoLite2Geolocator(files, config);
underTest = new GeolocationCache(new Locale(), config, geoLite2Geolocator, new IP2CGeolocator(), new TestPluginLogger());
underTest = new GeolocationCache(new Locale(), config, geoLite2Geolocator, new IP2CGeolocator(), new TestPluginLogger(), TestRunnableFactory.forSameThread());
underTest.enable();
assertTrue(underTest.canGeolocate());

View File

@ -69,16 +69,28 @@ abstract class Mocker {
"web/css/sb-admin-2.css",
"web/js/color-selector.js",
"web/js/graphs.js",
"web/js/network-values.js",
"web/js/pingTable.js",
"web/js/player-values.js",
"web/js/sb-admin-2.js",
"web/js/server-values.js",
"web/js/sessionAccordion.js",
"web/js/xmlhttprequests.js",
"web/js/graphs.js",
"web/vendor/bootstrap/js/bootstrap.bundle.min.js",
"web/vendor/datatables/jquery.dataTables.min.js",
"web/vendor/datatables/dataTables.bootstrap4.min.css",
"web/vendor/datatables/dataTables.bootstrap4.min.js",
"web/vendor/jquery/jquery.min.js",
"web/vendor/fullcalendar/fullcalendar.min.js",
"web/vendor/fullcalendar/fullcalendar.min.css",
"web/vendor/highcharts/drilldown.js",
"web/vendor/highcharts/highcharts-more.js",
"web/vendor/highcharts/highstock.js",
"web/vendor/highcharts/map.js",
"web/vendor/highcharts/no-data-to-display.js",
"web/vendor/highcharts/world.js",
"web/vendor/momentjs/moment.js"
}) {
withPluginFile(fileName);

View File

@ -18,8 +18,11 @@ package utilities.mocks.objects;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.PluginRunnable;
import com.djrapitops.plugin.task.PluginTask;
import com.djrapitops.plugin.task.RunnableFactory;
import org.mockito.Mockito;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
/**
@ -32,13 +35,42 @@ import static org.mockito.Mockito.mock;
*/
public class TestRunnableFactory extends RunnableFactory {
private boolean callOnSameThread;
public TestRunnableFactory() {
this(false);
}
private TestRunnableFactory(boolean callOnSameThread) {
this.callOnSameThread = callOnSameThread;
}
public static RunnableFactory forSameThread() {
return new TestRunnableFactory(true);
}
@Override
protected PluginRunnable createNewRunnable(String name, AbsRunnable absRunnable, long l) {
return mock(PluginRunnable.class);
protected PluginRunnable createNewRunnable(String name, AbsRunnable runnable, long l) {
PluginRunnable mock = mock(PluginRunnable.class);
if (callOnSameThread) {
lenient().when(mock.runTask()).then(invocation -> run(runnable));
lenient().when(mock.runTaskAsynchronously()).then(invocation -> run(runnable));
lenient().when(mock.runTaskLater(Mockito.anyLong())).then(invocation -> run(runnable));
lenient().when(mock.runTaskLaterAsynchronously(Mockito.anyLong())).then(invocation -> run(runnable));
lenient().when(mock.runTaskTimer(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> run(runnable));
lenient().when(mock.runTaskTimerAsynchronously(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> run(runnable));
}
return mock;
}
private PluginTask run(AbsRunnable runnable) {
runnable.run();
return null;
}
@Override
public void cancelAllKnownTasks() {
/* Nothing to cancel, nothing is actually run. */
}
}