public static void main(String[] args) {
AssociationTest test = new AssociationTest();
test.testUsingSimpleTypes();
test.testUsingCustomValueType();
test.testUsingComplexValueType();
test.printSummary();
}
private void testUsingSimpleTypes() { header("Starting -- testUsingSimpleTypes"); //Declare Association<String, Integer> assoc; String key = "A"; Integer value = 10; assoc = new Association<>(key, value); assertEquals(key, assoc.getKey()); assertEquals(value, assoc.getValue()); }
private void testUsingCustomValueType() { header("Starting -- testUsingCustomValueType"); //Declare Association<Integer, Employee> assoc; int id = 1; String nm = "Kofi Kingston"; Employee emp = new Employee(id, nm); //Construct assoc = new Association<>(id, emp); //Test assertEquals(id, assoc.getKey()); assertEquals(emp, assoc.getValue()); }
private void testUsingComplexValueType() { header("Starting -- testUsingComplexValueType"); //Declare Association<Integer, List<String>> assoc; List<String> players; Integer teamNumber; players = Arrays.asList("Riya", "Kofi", "Asha", "Chin"); teamNumber = 1; //Construct assoc = new Association<>(teamNumber, players); //Test assertEquals(teamNumber, assoc.getKey()); assertEquals(players, assoc.getValue()); }
package assoc.test; import java.util.Arrays; import java.util.List; import assoc.model.Association; import testutil.AbstractTest; import testutil.Employee; public class AssociationTest extends AbstractTest { //-------------------------- //Main (Entry Point) public static void main(String[] args) { AssociationTest test = new AssociationTest(); test.testUsingSimpleTypes(); test.testUsingCustomValueType(); test.testUsingComplexValueType(); test.printSummary(); } //-------------------------- //Tests private void testUsingSimpleTypes() { header("Starting -- testUsingSimpleTypes"); //Declare Association<String, Integer> assoc; String key = "A"; Integer value = 10; assoc = new Association<>(key, value); assertEquals(key, assoc.getKey()); assertEquals(value, assoc.getValue()); } private void testUsingCustomValueType() { header("Starting -- testUsingCustomValueType"); //Declare Association<Integer, Employee> assoc; int id = 1; String nm = "Kofi Kingston"; Employee emp = new Employee(id, nm); //Construct assoc = new Association<>(id, emp); //Test assertEquals(id, assoc.getKey()); assertEquals(emp, assoc.getValue()); } private void testUsingComplexValueType() { header("Starting -- testUsingComplexValueType"); //Declare Association<Integer, List<String>> assoc; List<String> players; Integer teamNumber; players = Arrays.asList("Riya", "Kofi", "Asha", "Chin"); teamNumber = 1; //Construct assoc = new Association<>(teamNumber, players); //Test assertEquals(teamNumber, assoc.getKey()); assertEquals(players, assoc.getValue()); } }