Skip to content

Commit

Permalink
[core] Force the agent tasks to have a name.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 24, 2020
1 parent 25a0895 commit 95f73e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ class AgentTask extends SRESpecificDataContainer {
val initiator : Object

/** Construct an AgentTask with the given initiator.
*
* @param name the name of the task.
* @param initiator the object that has initiated the execution of this task.
* If the value is {@code null} (the default value of the argument), the agent is assumed to
* be the initiator.
*/
new(initiator : Object = null) {
new(name : String, initiator : Object = null) {
assert name !== null
this.name = name
this.initiator = initiator
}

Expand Down Expand Up @@ -101,7 +105,7 @@ class AgentTask extends SRESpecificDataContainer {
* @return the name.
*/
def getName : String {
this.name
return this.name
}

/** Change the name of this task.
Expand All @@ -113,6 +117,7 @@ class AgentTask extends SRESpecificDataContainer {
@SuppressWarnings("use_reserved_sarl_annotation")
@PrivateAPI
def setTaskName(name : String) : void {
assert name !== null
this.name = name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
*/
package io.sarl.core.tests;

import static io.sarl.tests.api.tools.TestAssertions.assertException;
import static io.sarl.tests.api.tools.TestMockito.mock;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -51,11 +53,14 @@
@DisplayName("AgentTask")
public class AgentTaskTest extends AbstractSarlTest {

private String name;

private AgentTask task;

@BeforeEach
public void setUp() {
this.task = new AgentTask();
this.name = UUID.randomUUID().toString();
this.task = new AgentTask(this.name);
}

@Test
Expand Down Expand Up @@ -94,19 +99,26 @@ public void setGuard() {

@Test
public void getName() {
assertNull(this.task.getName());
assertSame(this.name, this.task.getName());
String name = UUID.randomUUID().toString();
this.task.setTaskName(name);
assertSame(name, this.task.getName());
}

@Test
public void setTaskName() {
@DisplayName("setTaskName(String)")
public void setTaskName_notNnull() {
String name = UUID.randomUUID().toString();
this.task.setTaskName(name);
assertSame(name, this.task.getName());
this.task.setTaskName(null);
assertNull(this.task.getName());
}

@Test
@DisplayName("setTaskName(null)")
public void setTaskName_null() throws Exception {
assertException(AssertionError.class, () -> {
this.task.setTaskName(null);
});
}

@Test
Expand Down

0 comments on commit 95f73e9

Please sign in to comment.