- ISecretSanta interface is used as a blueprint to implement two simple algorithms. There are two class files named: SimplePairing and ShufflePairing, both of which implement ISecretSanta. Each class file has their version of generateAssignments() method.
- Class SimplePairing uses Random class from Java to randomly choose an assignment/assignee/giftee for a particular participant.
- Class ShufflePairing uses Collection.shuffle() to shuffle assignmentsList. AssignmentsList is simply a ArrayList copy of participants array.
- Both implementations also ensures that:
- No participant is same as his/her assignee.
- The participants and their assignees are unique.
- It also logically follows that all the assignments are from the list of passed participants.
- A factory class called SecretSantaFactory is also defined. This class has a static factory method that is responsible for creating and returning one of the Secret Santa concrete classes. Using such design has the advantage of choosing any specific implementation as per requirement. The JUnit test class also utilizes this factory method to test the current implementation.
-
- Finally, the class "SecretSantaDemo" contains main method and uses our factory to choose and run a particular algorithm.
- Unit testing is performed using JUnit framework.
- A single test class is kept in the package santaProjectTests within the source folder. The test class is called SecretSantaTest. SecretSantaTest contains three different tests to check for the following cases:
- No participant is same as his/her assignment.
- The assignments are not simple left or right rotation of the participants.
- All assignments are unique, that is, no two assignees are the same.
9/02/2014 Added this line as a testing of using EGIT plugin in Eclipse Luna. (#Cerner #DevAcademy)