
Os números de 2010
Há 14 anos
NEWTON: As a nerd, I want to be cool having the possibility to have a specific night for a specific day.
I can have a night for a specific day that differs from the normal night for that day of the week. It is a special night occasion.
PASCAL: As a friend of a nerd, I want to know when a night happens.
Based on the name of the night I want to know when it happens.
Based on the day of the week I want to know what is the night of that day <(I don't want to avoid those nerd guys)>.
I want to know which night of a specific day.
public interface NightService {
/**
* Add a new night to the store. If the night is supplied with an ID it will be replaced.
* After the call to the registerNight method the Night object will have the ID filled.
* @param night night to be added.
*/
public void registerNight(Night night);
/**
* Replace the night stored. The provided night should have the id filled in order
* to have the date replaced correct.
* @param night night to be replaced.
*/
public void changeNight(Night night);
/**
* Returns the night by its unique identifier
* @param nightId identifier of the night.
* @return
* Night object, null if there isn't any night for that id.
*/
public Night findById(String nightId);
/**
* Returns the list of nights of the specified day of week.
*
*- The order returned by the find week day should be from the first include to the last one.
*
* @param dayOfWeek
* @return null when there isn't any night for the specified day of week, otherwise a list with the nights.
*/
public List<Night> findWeekDayNights(DayOfWeek dayOfWeek);
/**
* Returns the list of nights of the specified name, the name match is not case sensitive.
*
*- The order returned should be from the first include to the last one.
*
* @param dayOfWeek
* @return null when there isn't any night for the specified name, otherwise a list with the nights.
*/
public List<Night> findNightWithName(String nightName);
/**
* Returns the corresponding night for a specific day.
* @param date date of the night
* @return
* Night corresponding to the date, if there isn't any night for that day then returns null.
*/
public Night nightOf(Date date);
}
public class NightServiceTest {
private NightService nightService = null;
private TestUtils testUtils = null;
//... Code removed for simplicity
@Test
public void testRegisterNight() {
Night movieNight = testUtils.createNight(DayOfWeek.MONDAY, "MOVIE_NIGHT");
nightService.registerNight(movieNight);
Night movieNightRead = nightService.findById(movieNight.getId());
assertEquals(movieNight, movieNightRead);
}
@Test
public void testChangeNight() {
Night gameNight = testUtils.createNight(DayOfWeek.TUESDAY, "GAME_NIGHT");
nightService.registerNight(gameNight);
gameNight.setName("Man this is the really the GAME night");
nightService.changeNight(gameNight);
Night gameNightRead = nightService.findById(gameNight.getId());
assertEquals(gameNight, gameNightRead);
}
@Test
public void testFindNightById() {
Night wOwNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "WOW_NIGHT");
nightService.registerNight(wOwNight);
String validId = wOwNight.getId();
String invalidId = "invalidId";
Night validNight = nightService.findById(validId);
assertNotNull(validNight);
assertEquals(validId, validNight.getId());
Night invalidNight = nightService.findById(invalidId);
assertNull(invalidNight);
}
@Test
public void testFindWeekDayNights() {
//Create the nights
Night bownlingNight = testUtils.createNight(DayOfWeek.FRIDAY, "BOWNLING NIGHT");
Night arcadeNight = testUtils.createNight(DayOfWeek.FRIDAY, "ARCADE NIGHT");
Night kartNight = testUtils.createNight(DayOfWeek.FRIDAY, "KART NIGHT");
Night pizzaNight = testUtils.createNight(DayOfWeek.THURSDAY, "PIZZA NIGHT");
nightService.registerNight(bownlingNight);
nightService.registerNight(arcadeNight);
nightService.registerNight(kartNight);
nightService.registerNight(pizzaNight);
List<Night> mondayNights = nightService.findWeekDayNights(DayOfWeek.MONDAY);
List<Night> tuesdayNights = nightService.findWeekDayNights(DayOfWeek.TUESDAY);
List<Night> wednesdayNights = nightService.findWeekDayNights(DayOfWeek.WEDNESDAY);
List<Night> thursdayNights = nightService.findWeekDayNights(DayOfWeek.THURSDAY);
List<Night> fridayNights = nightService.findWeekDayNights(DayOfWeek.FRIDAY);
List<Night> saturdayNights = nightService.findWeekDayNights(DayOfWeek.SATURDAY);
List<Night> sundayNights = nightService.findWeekDayNights(DayOfWeek.SUNDAY);
assertNull(mondayNights);
assertNull(tuesdayNights);
assertNull(wednesdayNights);
assertNotNull(thursdayNights);
assertNotNull(fridayNights);
assertNull(saturdayNights);
assertNull(sundayNights);
assertEquals(thursdayNights.size(), 1);
assertEquals(fridayNights.size(), 2);
assertEquals(pizzaNight, thursdayNights.get(0));
//The order returned by the find week day should be from the first include to the last one.
assertEquals(bownlingNight, fridayNights.get(0));
assertEquals(arcadeNight, fridayNights.get(1));
assertEquals(kartNight, fridayNights.get(2));
}
@Test
public void testFindNightWithName() {
Night surprise_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "SURPRISE SURPRISE NIGHT");
Night big_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "BIG SURPRISE NIGHT");
Night surprise_surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "suprise surprise NIGHT");
Night double_Night_one = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");
Night double_Night_two = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");
nightService.registerNight(surprise_Surprise_Night);
nightService.registerNight(big_Surprise_Night);
nightService.registerNight(surprise_surprise_Night);
nightService.registerNight(double_Night_one);
nightService.registerNight(double_Night_two);
List<Night> nightsRead = nightService.findNightWithName("SURPRISE");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE NIGHT");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE SURPRISE");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE SURPRISE NIGHT");
assertEquals(nightsRead.get(0), surprise_Surprise_Night);
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));
nightsRead = nightService.findNightWithName("BIG SURPRISE NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertEquals(nightsRead.get(0), big_Surprise_Night);
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));
nightsRead = nightService.findNightWithName("suprise surprise NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertEquals(nightsRead.get(0),surprise_surprise_Night);
nightsRead = nightService.findNightWithName("DOUBLE NIGHT");
assertEquals(nightsRead.size(), 2);
assertEquals(nightsRead.get(0), double_Night_one);
assertEquals(nightsRead.get(1), double_Night_two);
}
@Test
public void testNightOf() {
//24.12.2010 is a friday
//29.02.2012 is a wednesday
//15.05.2010 is saturday
//22.05.2010 is saturday
Night gameNight = testUtils.createNight(DayOfWeek.FRIDAY, "GAME NIGHT");
Night thaiFoodNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "THAI FOOD NIGHT");
Night feverNight = testUtils.createNight(DayOfWeek.SATURDAY, "FEVER NIGHT");
nightService.registerNight(gameNight);
nightService.registerNight(thaiFoodNight);
nightService.registerNight(feverNight);
Calendar _15_05_2010 = Calendar.getInstance();
_15_05_2010.set(Calendar.DAY_OF_MONTH, 15);
_15_05_2010.set(Calendar.MONTH, Calendar.MAY);
_15_05_2010.set(Calendar.YEAR, 2010);
Calendar _22_05_2010 = Calendar.getInstance();
_22_05_2010.set(Calendar.DAY_OF_MONTH, 22);
_22_05_2010.set(Calendar.MONTH, Calendar.MAY);
_22_05_2010.set(Calendar.YEAR, 2010);
Calendar _24_12_2010 = Calendar.getInstance();
_24_12_2010.set(Calendar.DAY_OF_MONTH, 24);
_24_12_2010.set(Calendar.MONTH, Calendar.DECEMBER);
_24_12_2010.set(Calendar.YEAR, 2010);
Calendar _29_02_2012 = Calendar.getInstance();
_29_02_2012.set(Calendar.DAY_OF_MONTH, 29);
_29_02_2012.set(Calendar.MONTH, Calendar.FEBRUARY);
_29_02_2012.set(Calendar.YEAR, 2012);
Night night_24_12_2010 = nightService.nightOf(_24_12_2010.getTime());
Night night_29_02_2012 = nightService.nightOf(_29_02_2012.getTime());
Night night_15_05_2010 = nightService.nightOf(_15_05_2010.getTime());
Night night_22_05_2010 = nightService.nightOf(_22_05_2010.getTime());
assertEquals(gameNight, night_24_12_2010);
assertEquals(thaiFoodNight, night_29_02_2012);
assertEquals(feverNight, night_15_05_2010);
assertEquals(feverNight, night_22_05_2010);
}
}
Let's imagine a group of geek-nerd-friends, every week day they do something during the night. They have the Halo night, the comic store night, the movie night and so on, a full life. Because of that one of those guys wants to manage the nights, they want to know for each night: the participants, the activities of each one, time of those activites, how much people are involved in each activity and which nice widgets they have to use for those activities.
PYTHAGORAS: As a nerd, I want to organize the night and distribute the activities of that night across all my nerd friends.
- All the nights have a name, like Halo night or Comic store night.
- It always happens in a specific day of the week, like Halo night is always on wednesday.
- To have a nice night we should execute a group of activities (buy food, bring the game, etc).
- Each activity has one responsible.
- Each activity could need the help of 1 or more people.
- Each activity could require one or more widget to be executed (using the iPhone to find the pizza store, the teleport machine to arrive in time, etc).
- Each activity should be done to have a nice night.
- A night is ready to start when all the activities are done.
@Test
public void testIsNightReady() {
Night saturdayNightFever = new Night();
saturdayNightFever.setDayOfWeek(DayOfWeek.SATURDAY);
saturdayNightFever.setName("Saturday Night Fever revival night!");
//No activities means that the night is read to start
assertTrue(saturdayNightFever.isNightReady());
//Let's add a list of activities in the night
List<Activity> activitiesOfTheNight = new ArrayList<Activity>();
saturdayNightFever.setActivityList(activitiesOfTheNight);
assertTrue(saturdayNightFever.isNightReady());
//For a saturday night fever we need to practive dance listening the BeeGees K7
Activity practiceDance = new Activity();
practiceDance.setWhatShouldBeDone("Dance listening BeeGees K7");
practiceDance.setResponsible("me");
saturdayNightFever.getActivityList().add(practiceDance);
//And also get the nice white suite
Activity takeTheSuite = new Activity();
takeTheSuite.setWhatShouldBeDone("Take the white suite at mother's house");
takeTheSuite.setResponsible("me");
saturdayNightFever.getActivityList().add(takeTheSuite);
//And finally meet the girl
Activity meetTheGirl = new Activity();
meetTheGirl.setWhatShouldBeDone("Meet the girl at his house");
meetTheGirl.setResponsible("me");
saturdayNightFever.getActivityList().add(meetTheGirl);
//I have done none activity, so the night is not ready to start
assertFalse(saturdayNightFever.isNightReady());
//I've found the K7 and danced a lot, but still not ready.
practiceDance.setDone(true);
assertFalse(saturdayNightFever.isNightReady());
//Got the old father's white suite at moms house
takeTheSuite.setDone(true);
assertFalse(saturdayNightFever.isNightReady());
//Meet the girl
meetTheGirl.setDone(true);
//Now it is time to ROCK
assertTrue(saturdayNightFever.isNightReady());
}