I was unsure about some of the bold claims that Rebecca Black made in her latest hit video, so I wrote some unit tests for it. It turns out she is telling the truth!

public void testRebeccaIsntLying() {
    Calendar rebeccasCalendar =
        Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));

    // The song went viral on Friday, March 11, 2011
    rebeccasCalendar.set(2011, Calendar.MARCH, 11);

    // Yesterday was Thursday, Thursday
    rebeccasCalendar.add(Calendar.DAY_OF_MONTH, -1);
    assertEquals(Calendar.THURSDAY, rebeccasCalendar.get(Calendar.DAY_OF_WEEK));

    // Today i-is Friday, Friday (Partyin’)
    rebeccasCalendar.set(2011, 2, 11);
    assertEquals(Calendar.FRIDAY, rebeccasCalendar.get(Calendar.DAY_OF_WEEK));

    // Tomorrow is Saturday
    rebeccasCalendar.add(Calendar.DAY_OF_MONTH, 1);
    assertEquals(Calendar.SATURDAY, rebeccasCalendar.get(Calendar.DAY_OF_WEEK));

    // And Sunday comes afterwards
    rebeccasCalendar.add(Calendar.DAY_OF_MONTH, 1);
    assertEquals(Calendar.SUNDAY, rebeccasCalendar.get(Calendar.DAY_OF_WEEK));
  }

I sent this code out for review at work, and received quite a bit of insightful feedback from my co-workers:

  • As you mentioned two lines up, “yesterday was Thursday, Thursday”. Do we need to assertEquals twice?
  • I appreciate the attempt, but I have to say I find your test lacking. For starters, you only assert that yesterday was Thursday once.  I’d see two sequential assertions as the absolute minimum. More concerningly, a crucial property of the calendar is that it can be used to determine whether or not we need to get down.  Yet I see no assertion that we need to get down if and only if it is indeed Friday. Even if, in fact, it proves that no one is looking forward to the weekend, I don’t believe your test will catch it, to say nothing of our current observed state of partying. But these are just examples.  Who needs a Calendar object if this is all it’s good for?
  • Shouldn’t the time zone be determined dynamically? Rebecca may be traveling.
  • I’d ask you to assert that she has chosen the appropriate seat, but this may be out of the scope of this change.  A TODO will be fine.
  • While you are adding the above test, I would like you to consider updating this test case as well to assert that Rebecca is indeed looking forward to the weekend, as well as partying partying during the weekend, as appropriate given the day.
  • Can you devise tests for the following constraints made in the original documentation: 1. Gotta get down on Friday.  (e.g. ASSERT(didGetDown) 2. Everybody’s looking forward to the weekend.