Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Tests: Add test case for alphabetical scheduler #2698

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,6 +47,46 @@ public void test() throws Exception {
getControllerIds(sut));
}

@Test
public void testOnlyAlphabeticalOrdering() throws Exception {
final var controllerIds = new ArrayList<>(List.of(
"ctrlController1",
"a",
"aa",
"aA",
"ab",
"aB",
"A",
"0",
"1",
parapluplu marked this conversation as resolved.
Show resolved Hide resolved
"0controller",
"0Controller",
"bla",
"controller0",
"controller1",
"dontroller0",
"dontroller1",
"d0",
"D0",
"Z",
"z"));
final var sut = new SchedulerAllAlphabeticallyImpl();
final var test = new ComponentTest(sut) //
.addReference("componentManager", new DummyComponentManager());
controllerIds.forEach(controllerId -> test.addComponent(new DummyController(controllerId)));
test.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