From 930704c008c508544abd980326a91ee65d9cb1ed Mon Sep 17 00:00:00 2001 From: janekdererste Date: Sun, 14 Apr 2024 20:54:26 +0200 Subject: [PATCH] Switch matsim version to 2024 * remove compilation errors * Switch to junit 5 Test fails, because events are different --- pom.xml | 9 +++---- .../java/org/matsim/project/RunMatsim.java | 24 +----------------- .../matsim/project/RunMatsimApplication.java | 2 +- .../project/RunMatsimFromExamplesUtils.java | 2 +- .../org/matsim/project/RunMatsimTest.java | 25 ++++++++++--------- 5 files changed, 20 insertions(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index 6557e62a0..97cbd952a 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ - 15.0 + 2024.0 UTF-8 UTF-8 @@ -54,10 +54,9 @@ - - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-engine + 5.10.2 test diff --git a/src/main/java/org/matsim/project/RunMatsim.java b/src/main/java/org/matsim/project/RunMatsim.java index 74b41734f..ae501a05c 100644 --- a/src/main/java/org/matsim/project/RunMatsim.java +++ b/src/main/java/org/matsim/project/RunMatsim.java @@ -18,34 +18,12 @@ * *********************************************************************** */ package org.matsim.project; -import com.google.inject.internal.asm.$Type; -import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.otfvis.OTFVisLiveModule; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup.SnapshotStyle; -import org.matsim.core.config.groups.QSimConfigGroup.TrafficDynamics; -import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; -import org.matsim.core.config.groups.StrategyConfigGroup; import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule; import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.collections.CollectionUtils; -import org.matsim.vehicles.VehicleType; -import org.matsim.vehicles.VehicleUtils; -import org.matsim.vis.otfvis.OTFVisConfigGroup; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Set; /** * @author nagel @@ -62,7 +40,7 @@ public static void main(String[] args) { config = ConfigUtils.loadConfig( args ); } - config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); + config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); // possibly modify config here diff --git a/src/main/java/org/matsim/project/RunMatsimApplication.java b/src/main/java/org/matsim/project/RunMatsimApplication.java index 82f185876..3420d4688 100644 --- a/src/main/java/org/matsim/project/RunMatsimApplication.java +++ b/src/main/java/org/matsim/project/RunMatsimApplication.java @@ -43,7 +43,7 @@ public static void main(String[] args) { @Override protected Config prepareConfig(Config config) { - config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); + config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); // possibly modify config here diff --git a/src/main/java/org/matsim/project/RunMatsimFromExamplesUtils.java b/src/main/java/org/matsim/project/RunMatsimFromExamplesUtils.java index d660adcff..8f8c471af 100644 --- a/src/main/java/org/matsim/project/RunMatsimFromExamplesUtils.java +++ b/src/main/java/org/matsim/project/RunMatsimFromExamplesUtils.java @@ -18,7 +18,7 @@ public static void main( String[] args ){ URL url = IOUtils.extendUrl( context, "config.xml" ); Config config = ConfigUtils.loadConfig( url ); - config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); + config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); // --- diff --git a/src/test/java/org/matsim/project/RunMatsimTest.java b/src/test/java/org/matsim/project/RunMatsimTest.java index cbab6ffdc..ae97a71e9 100644 --- a/src/test/java/org/matsim/project/RunMatsimTest.java +++ b/src/test/java/org/matsim/project/RunMatsimTest.java @@ -19,9 +19,8 @@ package org.matsim.project; import org.apache.logging.log4j.LogManager; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; @@ -31,17 +30,21 @@ import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.testcases.MatsimTestUtils; -import org.matsim.utils.eventsfilecomparison.EventsFileComparator; +import org.matsim.utils.eventsfilecomparison.ComparisonResult; import java.net.URL; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * @author nagel * */ public class RunMatsimTest { - - @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; + + @RegisterExtension + public MatsimTestUtils utils = new MatsimTestUtils() ; @Test // @Ignore("OTFVis does not work on build server") PLEASE DO NOT DO THIS. Rather comment out OTFVis line in RunMatsim#main. kai, oct'22 @@ -65,7 +68,7 @@ public final void test() { for ( Id personId : expected.getPersons().keySet()) { double scoreReference = expected.getPersons().get(personId).getSelectedPlan().getScore(); double scoreCurrent = actual.getPersons().get(personId).getSelectedPlan().getScore(); - Assert.assertEquals("Scores of person=" + personId + " are different", scoreReference, scoreCurrent, MatsimTestUtils.EPSILON); + assertEquals(scoreReference, scoreCurrent, 0.001, "Scores of person=" + personId + " are different"); } @@ -77,17 +80,15 @@ public final void test() { { String expected = utils.getInputDirectory() + "/output_events.xml.gz" ; String actual = utils.getOutputDirectory() + "/output_events.xml.gz" ; - EventsFileComparator.Result result = EventsUtils.compareEventsFiles( expected, actual ); - Assert.assertEquals( EventsFileComparator.Result.FILES_ARE_EQUAL, result ); + ComparisonResult result = EventsUtils.compareEventsFiles( expected, actual ); + assertEquals( ComparisonResult.FILES_ARE_EQUAL, result ); } } catch ( Exception ee ) { LogManager.getLogger(this.getClass() ).fatal("there was an exception: \n" + ee ) ; // if one catches an exception, then one needs to explicitly fail the test: - Assert.fail(); + fail(); } - - } }