Sensor { @Override public boolean equals(Object o) { if (o == null) return false; if (!(o instanceof Sensor)) return false; Sensor sensor = (Sensor)o; return sensor.getSensorID() == this.getSensorID(); } protected  Sensor(String name, int sensorID, StatusCache cache, EventProducer eventProducer, int commandID,
                   Map<String, String> sensorProperties, EnumSensorType sensorType); static boolean isUnknownSensorValue(String value); String getName(); int getSensorID(); int getCommandID(); Map<String, String> getProperties(); void update(String state); boolean isEventListener(); boolean isPolling(); void start(); void stop(); boolean isRunning(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object o); @Deprecated final static String UNKNOWN_STATUS; @Deprecated final static String RANGE_MIN_STATE; @Deprecated final static String RANGE_MAX_STATE; }
@Test public void testEquals() { EventProducer ep1 = new TestEventProducer1(); EventProducer ep2 = new TestEventProducer2(); Sensor s1 = new RangeSensor("range", 1, cache, ep1, 1, -50, 50); Sensor s2 = new LevelSensor("level", 1, cache, ep2, 1); Sensor s3 = new RangeSensor("range", 1, cache, ep1, 1, -20, 20); Assert.assertTrue(s1.equals(s1)); Assert.assertTrue(s1.equals(s2)); Assert.assertTrue(s2.equals(s1)); Assert.assertTrue(s1.equals(s3)); Assert.assertTrue(s3.equals(s1)); Assert.assertTrue(s3.equals(s2)); Assert.assertTrue(s2.equals(s3)); Assert.assertTrue(s2.equals(s2)); Assert.assertTrue(s3.equals(s3)); Assert.assertTrue(s1.hashCode() == s2.hashCode()); Assert.assertTrue(s2.hashCode() == s3.hashCode()); Sensor s4 = new RangeSensor("range", 2, cache, ep1, 1, -50, 50); Assert.assertFalse(s1.equals(s4)); Assert.assertFalse(s4.equals(s1)); Assert.assertFalse(s2.equals(s4)); Assert.assertFalse(s4.equals(s2)); Assert.assertFalse(s3.equals(s4)); Assert.assertFalse(s4.equals(s3)); }