Quick Index
Code Explanation


Greetings, I am AssociationTest.

My Job is to construct Association object instances and hammer on them. I love finding bugs.

I also am a good place to learn about how to use an Association.

My superclass is Abstract Test.

Read more about me below.

  • Run the tests
  • Show the testing summary
	public static void main(String[] args)  {
		AssociationTest test = new AssociationTest();
		test.testUsingSimpleTypes();
		test.testUsingCustomValueType();
		test.testUsingComplexValueType();
		test.printSummary();
	}
Simplest test we can think of.
Construct an Association with a String key and Integer value.
Test the Association object.
The helper method assertEquals is used
	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());
	}
Often the value type will be a customized type like in this test (Employee).
	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());
	}
Often the value will be a complex object like in this test.
The value for this assoc is a list
	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());
	}

Complete Source Code


Here is my code.

Have Fun.

Your friend,
AssociationTest

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());
	}

}