/** * Tests that IAE is thrown when there are too many time models. */ @Test public void testTooManyTimeModels() { final Scenario s = Scenario.builder() .addModel(TimeModel.builder()) .addModel(TimeModel.builder().withRealTime()) .build(); boolean fail = false; try { ScenarioConverters.toRealtime().apply(s); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()) .isEqualTo("More than one time model is not supported."); } assertThat(fail).isTrue(); } }
/** * Tests that when no time model is available, a default is added. */ @Test public void testEmpty() { final Scenario empty = Scenario.builder().build(); assertThat(empty.getModelBuilders()).isEmpty(); final Scenario convertedEmpty = verifyNotNull(ScenarioConverters.toRealtime().apply(empty)); assertThat(convertedEmpty.getModelBuilders()) .contains(TimeModel.builder() .withRealTime() .withStartInClockMode(ClockMode.SIMULATED)); }
/** * Tests {@link ScenarioIO#readerAdapter(com.google.common.base.Function)}. * @throws IOException When IO fails. */ @Test public void testReaderAdapter() throws IOException { final Scenario s = Scenario.builder() .addModel(TimeModel.builder().withTickLength(7L)) .build(); final Path tmpDir = Files.createTempDirectory("rinsim-scenario-io-test"); final Path file = Paths.get(tmpDir.toString(), "test.scen"); ScenarioIO.write(s, file); final Scenario out = ScenarioIO.reader().apply(file); final Scenario convertedOut = verifyNotNull(ScenarioIO.readerAdapter(ScenarioConverters.toRealtime()) .apply(file)); assertThat(s).isEqualTo(out); assertThat(s).isNotEqualTo(convertedOut); assertThat(convertedOut.getModelBuilders()) .contains(TimeModel.builder() .withRealTime() .withStartInClockMode(ClockMode.SIMULATED) .withTickLength(7L)); Files.delete(file); Files.delete(tmpDir); }
/** * Tests that when a time model already exists, its properties are copied. */ @Test public void testCopyProperties() { final Scenario s = Scenario.builder() .addModel(TimeModel.builder() .withTickLength(754L) .withTimeUnit(NonSI.DAY)) .addModel(CommModel.builder()) .build(); final Scenario converted = verifyNotNull(ScenarioConverters.toRealtime().apply(s)); assertThat(converted.getModelBuilders()) .contains(TimeModel.builder() .withRealTime() .withStartInClockMode(ClockMode.SIMULATED) .withTickLength(754L) .withTimeUnit(NonSI.DAY)); }