Planned Unit Tests for Bake-off Code 2
I'll need 'session' objects for both Google and Outlook. Sessions can do the following:
- Start-up
- Shut-down
- Give me the full calendar
- Make the full calendar look like this
I'm deliberately keeping sessions as stupid as possible. -------------------------------------------- OBSOLETE CONTENT FOLLOWS
Now I'll begin to flesh out Calendar.merge. For starters, I'll create an AbstractCalendar class and specialize it into GoogleCalendar and OutlookCalendar. Calendars will support the following methods (for now):
- load
- merge
- assign
- persist
- entry_count
Load and persist will return the specialized object; merge will return the abstract calendar. Since I'm doing test-first, I'll need to implement the pseudo-code shown below. For starters, I'll implement the simplest (stupidest) algorithm of rebuilding a calendar store from scratch on calls to the assign+persist methods. Test the 'shape' of the load method:
- validate that load returns a GoogleCalendar when called on a GoogleCalendar.
- Validate that load returns an OutlookCalendar when called on an OutlookCalendar
- Validate that load fails when called on an AbstractCalendar
- Validate that load returns a GoogleCalendar when called on an AbstractCalendar, constructed as a GoogleCalendar. Oops! Wait... That only makes sense with a statically typed language.
Test the load method's ability to retrieve mocked data:
- Validate that load returns a GoogleCalendar with 0 entries when called on a GoogleCalendar with mocks to return 0 entries.
- Validate that load returns an OutlookCalendar with 0 entries when called on an OutlookCalendar with mocks to return 0 entries.
- validate that load returns a GoogleCalendar with 3 entries when called on a GoogleCalendar with mocks to return 3 entries.
- Validate that load returns an OutlookCalendar with 3 entries when called on an OutlookCalendar with mocks to return 3 entries.
- Validate that load throws an appropriate error when called on a GoogleCalendar with no network connection.
- Validate that load throws an appropriate error when called on an OutlookCalendar when OutlookCalendar can't connect to the Calendar folder in Outlook.
Test the merge method:
- Merging 2 OutlookCalendars with 3 non-overlapping entries in each yields an AbstractCalendar with 6 entries.
- Merging 2 GoogleCalendars with 3 non-overlapping entries in each yields an AbstractCalendar with 6 entries.
- Merging 2 OutlookCalendars with 3 overlapping entries in each yields an AbstractCalendar with 3 entries.
- Merging 2 GoogleCalendars with 3 overlapping entries in each yields an AbstractCalendar with 3 entries.
- Merging 2 OutlookCalendars with 3 entries (two of which overlap) in each yields an AbstractCalendar with 4 entries.
- Merging 2 GoogleCalendars with 3 entries (one of which overlaps) in each yields an AbstractCalendar with 5 entries.
- Merging an OutlookCalendar with 3 entries into a GoogleCalendar with 3 entries (two of which overlap) yields an AbstractCalendar with 4 entries.
- Merging a GoogleCalendar with 3 entries into an OutlookCalendar with 3 entries (one of which overlaps) yields an AbstractCalendar with 5 entries.
Test the assign method:
- Assigning an AbstractCalendar with 0 entries to a GoogleCalendar with 0 entries yields a GoogleCalendar with 0 entries.
- Assigning an AbstractCalendar with 0 entries to an OutlookCalendar with 0 entries yields an OutlookCalendar with 0 entries.
- Assigning an AbstractCalendar with 0 entries to a GoogleCalendar with 3 entries yields a GoogleCalendar with 0 entries.
- Assigning an AbstractCalendar with 0 entries to an OutlookCalendar with 3 entries yields an OutlookCalendar with 0 entries.
- Assigning an AbstractCalendar with 2 entries to a GoogleCalendar yields a GoogleCalendar with 2 entries.
- Assigning an AbstractCalendar with 3 entries to an OutlookCalendar yields an OutlookCalendar with 3 entries.
- Assigning a GoogleCalendar with 3 entries to a GoogleCalendar yields a GoogleCalendar with 3 entries.
- Assigning an OutlookCalendar with 2 entries to an OutlookCalendar yields an OutlookCalendar with 2 entries.
- Assigning a GoogleCalendar with 3 entries to an OutlookCalendar yields an OutlookCalendar with 3 entries.
- Assigning an OutlookCalendar with 2 entries to a GoogleCalendar yields a GoogleCalendar with 2 entries.
Test the persist method using mocks:
- Persisting an empty AbstractCalendar throws an appropriate error.
- Persisting an empty OutlookCalendar proceeds without throwing an error, makes 1 call to the delete-everything-in-Outlook mock, and zero calls to the add-to-Outlook mock and the replace-in-Outlook mock.
- Persisting an empty GoogleCalendar proceeds without throwing an error, makes 1 call to the delete-everything-in-Google mock, and zero calls to the add-to-Google mock and the replace-in-Google mock.
- Persisting a non-empty AbstractCalendar throws an appropriate error.
- Persisting an OutlookCalendar with 3 entries proceeds without throwing an error, makes 1 call to the delete-everything-in-Outlook mock, and three calls to the add-to-Outlook mock and zero to the replace-in-Outlook mock.
- Persisting a GoogleCalendar with 2 entries proceeds without throwing an error, makes 1 call to the delete-everything-in-Google mock, and 3 calls to the add-to-Google mock and zero to the replace-in-Google mock.
Note: entry_count will get fully tested in the above tests.

Delicious
Digg
Reddit