Skip to content

Commit

Permalink
fix broken tests for jpo-ode-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mwodahl committed Jun 29, 2023
1 parent ae95987 commit 00ba4d6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package us.dot.its.jpo.ode.plugin.generic;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -39,43 +40,45 @@ public class PluginFactoryTest {
@Mocked//(stubOutClassInitialization = true)
final LoggerFactory unused = null;

@Test(expected = ClassCastException.class)
@Test
public void testGetPluginByName(@Mocked Logger logger)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
assertThrows(ClassCastException.class, () -> {
String coderClassName = "us.dot.its.jpo.ode.plugin.generic.TestPlugin";

String coderClassName = "us.dot.its.jpo.ode.plugin.generic.TestPlugin";

OdePlugin result = PluginFactory.getPluginByName(coderClassName);
assertNotNull(result);
//assertTrue(result instanceof TestPlugin);
new Verifications() {
{
logger.info("Getting Plugin: {}", coderClassName);
logger.info("Classpath: {}", anyString);
logger.info("Getting class: {}", anyString);
logger.info("creating an instance of: {}", any);
}
};
OdePlugin result = PluginFactory.getPluginByName(coderClassName);
assertNotNull(result);
//assertTrue(result instanceof TestPlugin);
new Verifications() {
{
logger.info("Getting Plugin: {}", coderClassName);
logger.info("Classpath: {}", anyString);
logger.info("Getting class: {}", anyString);
logger.info("creating an instance of: {}", any);
}
};
});
}


@Test(expected = ClassCastException.class)
@Test
public void testException(@Mocked Logger logger)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
assertThrows(ClassCastException.class, () -> {
String coderClassName = "bogus.BogusClass";

String coderClassName = "bogus.BogusClass";

OdePlugin result = PluginFactory.getPluginByName(coderClassName);
assertNotNull(result);
assertTrue(result instanceof J2735Bsm);
new Verifications() {
{
logger.info("Getting Plugin: {}", coderClassName);
logger.error(anyString, (Exception) any);
logger.info("Classpath: {}", anyString);
logger.info("Getting class: {}", anyString);
logger.info("creating an instance of: {}", any);
}
};
OdePlugin result = PluginFactory.getPluginByName(coderClassName);
assertNotNull(result);
assertTrue(result instanceof J2735Bsm);
new Verifications() {
{
logger.info("Getting Plugin: {}", coderClassName);
logger.error(anyString, (Exception) any);
logger.info("Classpath: {}", anyString);
logger.info("Getting class: {}", anyString);
logger.info("creating an instance of: {}", any);
}
};
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,18 +62,20 @@ public void testSetChosenField() {
@Mocked//(stubOutClassInitialization = true)
final LoggerFactory unused = null;

@Test(expected = NoSuchFieldException.class)
@Test
public void testSetChosenFieldException2(@Mocked Logger logger) throws NoSuchFieldException {
new Expectations() {
{
logger.error(anyString, (Exception) any);
;
result = new NoSuchFieldException();
}
};
j2735Choice.setChosenFieldName("childField");
assertEquals("childField", j2735Choice.getChosenFieldName());
assertThrows(NoSuchFieldException.class, () -> {
new Expectations() {
{
logger.error(anyString, (Exception) any);
;
result = new NoSuchFieldException();
}
};
j2735Choice.setChosenFieldName("childField");
assertEquals("childField", j2735Choice.getChosenFieldName());

j2735Choice.setChosenField("wrongField", "childFieldValue");
j2735Choice.setChosenField("wrongField", "childFieldValue");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import us.dot.its.jpo.ode.plugin.j2735.OdeGeoRegion.GeoRegionException;

Expand All @@ -49,7 +49,7 @@ public class OdeGeoRegionTest {

private OdeGeoRegion testRegion;

@Before
@BeforeEach
public void setup() throws GeoRegionException {
region1 = new OdeGeoRegion();
region2 = new OdeGeoRegion("44.44,-55.55 22.22, -33.33");
Expand Down Expand Up @@ -230,7 +230,7 @@ public void testContainsPosition3DPasses() throws GeoRegionException {
/**
* Create a known geo region (roughly Pennsylvania)
*/
@Before
@BeforeEach
public void setupOdeGeoRegion() {

BigDecimal nwLat = BigDecimal.valueOf(42.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.node.ObjectNode;

Expand Down Expand Up @@ -86,21 +87,21 @@ public void testOptionalFields() {
assertEquals(J2735ResponseType.SLOWMOVING, actualValue.getResponseType());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testOptionalFieldsWithInvalidSSPRights() {

ObjectNode testInput = JsonUtils.newNode();
testInput.put("sspRights", 8);
testInput.set("sirenUse", JsonUtils.newNode().put("notInUse", true));
testInput.set("lightsUse", JsonUtils.newNode().put("arrowSignsActive", true));
testInput.set("multi", JsonUtils.newNode().put("singleVehicle", true));

// optional fields
testInput.set("events", JsonUtils.newNode().put("sspRights", 32).put("event", "001000"));
testInput.set("responseType", JsonUtils.newNode().put("slowMoving", true));

EmergencyDetailsBuilder.genericEmergencyDetails(testInput);

assertThrows(IllegalArgumentException.class, () -> {
ObjectNode testInput = JsonUtils.newNode();
testInput.put("sspRights", 8);
testInput.set("sirenUse", JsonUtils.newNode().put("notInUse", true));
testInput.set("lightsUse", JsonUtils.newNode().put("arrowSignsActive", true));
testInput.set("multi", JsonUtils.newNode().put("singleVehicle", true));
// optional fields
testInput.set("events", JsonUtils.newNode().put("sspRights", 32).put("event", "001000"));
testInput.set("responseType", JsonUtils.newNode().put("slowMoving", true));

EmergencyDetailsBuilder.genericEmergencyDetails(testInput);
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.node.ObjectNode;

Expand All @@ -19,7 +20,7 @@ public class GeoRegionBuilderTest {

private OdeGeoRegion odeGeoRegion;

@Before
@BeforeEach
public void setup() {
OdePosition3D nwCorner = new OdePosition3D(BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE);
OdePosition3D seCorner = new OdePosition3D(BigDecimal.TEN, BigDecimal.TEN, BigDecimal.TEN);
Expand Down

0 comments on commit 00ba4d6

Please sign in to comment.