Skip to content

Commit

Permalink
Unit Tests: Add test case for alphabetical scheduler (#2698)
Browse files Browse the repository at this point in the history
* Unit Tests: Add test case for alphabetical scheduler
* Improve test coverage; fix Eclipse autoformat

---------

Co-authored-by: Felix Remmel <[email protected]>
Co-authored-by: Stefan Feilmeier <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 99f1b6d commit 051489e
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Test;
Expand All @@ -25,7 +27,7 @@ public class SchedulerAllAlphabeticallyImplTest {
private static final String CTRL4_ID = "ctrl4";

@Test
public void test() throws Exception {
public void testWithFixedPriorities() throws Exception {
final SchedulerAllAlphabetically sut = new SchedulerAllAlphabeticallyImpl();
new ComponentTest(sut) //
.addReference("componentManager", new DummyComponentManager()) //
Expand All @@ -36,15 +38,55 @@ public void test() throws Exception {
.addComponent(new DummyController(CTRL4_ID)) //
.activate(MyConfig.create() //
.setId(SCHEDULER_ID) //
.setControllersIds(CTRL2_ID, CTRL1_ID) //
.setControllersIds(CTRL2_ID, CTRL1_ID, "") //
.build())
.next(new TestCase());
.next(new TestCase()) //
.deactivate();

assertEquals(//
Arrays.asList(CTRL2_ID, CTRL1_ID, CTRL0_ID, CTRL3_ID, CTRL4_ID), //
getControllerIds(sut));
}

@Test
public void testOnlyAlphabeticalOrdering() throws Exception {
final var controllerIds = new ArrayList<>(List.of(//
"ctrlController1", //
"a", //
"aa", //
"aA", //
"ab", //
"aB", //
"A", //
"0", //
"1", //
"0controller", //
"0Controller", //
"bla", //
"controller0", //
"controller1", //
"dontroller0", //
"dontroller1", //
"d0", //
"D0", //
"Z", //
"z"));
final var sut = new SchedulerAllAlphabeticallyImpl();
final var test = new ComponentTest(sut); //
controllerIds.forEach(controllerId -> test.addComponent(new DummyController(controllerId)));
test //
.addReference("componentManager", new DummyComponentManager()) //
.activate(MyConfig.create() //
.setId(SCHEDULER_ID) //
.setControllersIds() //
.build()) //
.next(new TestCase());

Collections.sort(controllerIds);

assertEquals(controllerIds, getControllerIds(sut));
}

private static List<String> getControllerIds(Scheduler scheduler) throws OpenemsNamedException {
return scheduler.getControllers().stream() //
.toList();
Expand Down

0 comments on commit 051489e

Please sign in to comment.