Created
April 24, 2017 14:00
-
-
Save Gregliest/c8fc7a7796c9f4567f98f3183c0a139c to your computer and use it in GitHub Desktop.
Example, making JUnit read a little more like Rspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Describe: the TripRequest model | |
@RunWith(HierarchicalContextRunner.class) | |
public class TripRequestTest { | |
static Instant now; | |
static Instant past; | |
static Instant future; | |
TimeSlot timeSlotNow; | |
TimeSlot timeSlotPast; | |
TimeSlot timeSlotFuture; | |
@BeforeClass | |
public static void setupClass() { | |
now = Instant.now(); | |
past = now.minus(10, ChronoUnit.MINUTES); | |
future = now.plus(10, ChronoUnit.MINUTES); | |
} | |
// Create time slots | |
@Before | |
public void setup() { | |
timeSlotNow = MockTimeSlot.generateTimeSlot(now); | |
timeSlotPast = MockTimeSlot.generateTimeSlot(past); | |
timeSlotFuture = MockTimeSlot.generateTimeSlot(future); | |
} | |
// Context getFirstTimeSlot() | |
public class Method_getFirstTimeSlot { | |
TripRequest request; | |
@Test | |
public void givenNoTimeSlots_returnNull() { | |
request = new TripRequest(); | |
assertThat(request.getFirstTimeSlot(), Matchers.nullValue()); | |
} | |
@Test | |
public void givenOneTimeSlot_returnsTimeSlot() { | |
request = new TripRequest(); | |
request.addTimeSlot(timeSlotNow); | |
assertEquals(request.getFirstTimeSlot(), timeSlotNow); | |
} | |
@Test | |
public void givenMultipleTimeSlots_returnsFirst() { | |
request = new TripRequest(); | |
request.setTimeSlots(Lists.newArrayList(timeSlotNow, timeSlotPast, timeSlotFuture)); | |
assertEquals(request.getFirstTimeSlot(), timeSlotPast); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment