Skip to content

Commit

Permalink
Update CarmaCloudMessageAmbassadorTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kruegersp authored Apr 12, 2024
1 parent f635f97 commit 7d08972
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.mosaic.rti.api.InternalFederateException;
import org.eclipse.mosaic.rti.api.IllegalValueException;
import org.eclipse.mosaic.rti.TIME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -26,20 +27,24 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.internal.util.reflection.FieldSetter;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;


/**
* Tests for {@link CarmaCloudMessageAmbassador}.
*/
public class CarmaCloudMessageAmbassadorTest {

private final TemporaryFolder temporaryFolder = new TemporaryFolder();

private CarmaCloudMessageAmbassador ambassador;
/**
* {@link CarmaCloudInstanceManager} mock.
Expand All @@ -61,11 +66,21 @@ public void setUp() throws IOException, NoSuchFieldException, InternalFederateEx
CarmaCloudRegistrationMessage message = new CarmaCloudRegistrationMessage("", "");
registrationMessages = new ArrayList<>();
registrationMessages.add(message);

ambassador = new CarmaCloudMessageAmbassador(new AmbassadorParameter("carmacloud",
temporaryFolder.newFile("carmacloud/carmacloud_config.json")));

FieldSetter.setField(ambassador, ambassador.getClass().getDeclaredField("carmaCloudRegistrationReceiver"), receiverMock);
FieldSetter.setField(ambassador, ambassador.getClass().getDeclaredField("carmaCloudInstanceManager"), instanceManagerMock);
}

@Test
public void testInitialize() throws InternalFederateException, IllegalValueException {
assertTrue(true);
// Test initialize method
ambassador.initialize(0, 100 * TIME.SECOND);
verify(rtiMock, times(1)).requestAdvanceTime(eq(0L), eq(0L), eq((byte) 1));
// cleanup threads and sockets
ambassador.close();
}

@Test
Expand Down

0 comments on commit 7d08972

Please sign in to comment.