Reference Guide

Table Of Contents
application source code included with the HP VAN SDN Controller SDK. SwitchTest should be
located under hm-model/src/test/java/com/hp/hm/model directory.
SwitchTest.java:
package com.hp.hm.model;
import com.hp.test.BeanTest;
import com.hp.test.EqualityTester;
import com.hp.test.SerializabilityTester;
public class SwitchTest {
...
@Test
public void testGettersAndSetters() throws Exception {
Switch device = //... create an instance
BeanTest.testGettersAndSetters(device);
}
@Test
public void testEqualsAndHashcode() {
Switch base = //... create the base object
Switch equals1 = //... create an object equal to the base
Switch equals2 = //... create an object equal to the base
Switch unequal = //... create an object unequal to the base
EqualityTester.testEqualsAndHashCode(base, equals1,
equals2, unequal);
}
@Test
public void testSerialization() {
Switch device = //... create with attributes set to non-null values
SerializabilityTester.testSerialization(device);
}
}
BeanTest utility class—A rudimentary facility for generic testing of basic bean getter and setter
functionality. It uses reflection to locate matching getter/setter pairs in the supplied bean instance.
EqualityTester class—Verifies the equivalence relation on non-null object references as
documented in the Java Object.equals(Object) method; it follows the equals contract and makes
sure its properties hold: reflexive, symmetric, transitive, consistent and non-null reference.
SerializabilityTester class—Serializes and deserializes the object being tested looking for
serialization failures (java.io.NotSerializableException) which are thrown when an instance is
required to have a Serializable interface. It is crucial to set a non-null value to all non-transient
attributes in the object under test, otherwise serialization failures won’t be detected.
155