From 8337c64669c9dd40994ca78bbc47daad9ba326c0 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 28 Jul 2023 14:17:28 -0400 Subject: [PATCH] Fixed unit test and added hash method for sonar scanner code smells --- ...InfrastructureRegistrationMessageTest.java | 22 ++++++++----------- .../lib/objects/detector/DetectedObject.java | 21 ++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/co-simulation/fed/mosaic-infrastructure/src/test/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessageTest.java b/co-simulation/fed/mosaic-infrastructure/src/test/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessageTest.java index 710509f8..775358a7 100644 --- a/co-simulation/fed/mosaic-infrastructure/src/test/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessageTest.java +++ b/co-simulation/fed/mosaic-infrastructure/src/test/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessageTest.java @@ -28,6 +28,7 @@ public class InfrastructureRegistrationMessageTest { @Test public void testGetterSettersConstructor() { + // Test Constructor ArrayList sensors = new ArrayList<>(); sensors.add( new Detector( @@ -43,20 +44,15 @@ public void testGetterSettersConstructor() { 8642, CartesianPoint.xy(1, 2), sensors); - assertEquals(message.getInfrastructureId(), "rsu_1"); - assertEquals(message.getRxMessageIpAddress(), "127.0.0.1" ); - assertEquals(message.getRxMessagePort(), 4567); - assertEquals(message.getTimeSyncPort(), 5678); - assertEquals(message.getSimulatedInteractionPort(), 8642); - assertEquals(message.getLocation(), CartesianPoint.xy(1,2)); - assertEquals(message.getSensors(), sensors); - - + // Test Getter + assertEquals("rsu_1",message.getInfrastructureId()); + assertEquals("127.0.0.1", message.getInfrastructureId() ); + assertEquals(4567, message.getRxMessagePort()); + assertEquals(5678, message.getTimeSyncPort()); + assertEquals(8642, message.getSimulatedInteractionPort()); + assertEquals(CartesianPoint.xy(1,2), message.getLocation()); + assertEquals(sensors, message.getSensors()); } - @Test - public void testToString() { - - } } diff --git a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java index d1b5e7a4..0530f81f 100644 --- a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java +++ b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java @@ -126,6 +126,27 @@ public Vector3d getAngularVelocity() { public Size getSize() { return size; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + long temp; + temp = Double.doubleToLongBits(confidence); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + ((sensorId == null) ? 0 : sensorId.hashCode()); + result = prime * result + ((projString == null) ? 0 : projString.hashCode()); + result = prime * result + ((objectId == null) ? 0 : objectId.hashCode()); + result = prime * result + ((position == null) ? 0 : position.hashCode()); + result = prime * result + Arrays.hashCode(positionCovariance); + result = prime * result + ((velocity == null) ? 0 : velocity.hashCode()); + result = prime * result + Arrays.hashCode(velocityCovariance); + result = prime * result + ((angularVelocity == null) ? 0 : angularVelocity.hashCode()); + result = prime * result + Arrays.hashCode(angularVelocityCovariance); + result = prime * result + ((size == null) ? 0 : size.hashCode()); + return result; + } @Override public boolean equals(Object obj) {