def CreateGapLease(self): data_file = open('/leases/gap', 'w+') data_file.write(contract_data) data_file.close()def testCreateGapLease(self): contract_writer.CreateGapLease() self.assertEqual(ReadFileContents('/leases/gap'), contract_data)
def testCreateGapLease(self): if os.path.exists(lease_file): RemoveFile(lease_file) ...
def CreateGapLease(self, lease_path=None): if lease_path is None: lease_path = '/leases/gap' ...
def testCreateGapLease(self): lease_file = os.path.join(FLAGS.test_tmpdir, 'gap') contract_writer.CreateGapLease(lease_path=lease_file) self.assertEqual(ReadFileContents(lease_file), contract_data)
/** Return a date object representing the start of the next minute from now */public Date nextMinuteFromNow() { long nowAsMillis = System.currentTimeMillis(); Date then = new Date(nowAsMillis + 60000); then.setSeconds(0); then.setMilliseconds(0); return then;}
public Date minuteAfter(Date now) { Date then = new Date(now.getTime() + 60000); then.setSeconds(0); then.setMilliseconds(0); return then;}// Retain original functionality@Deprecated public Date nextMinuteFromNow() { return minuteAfter(new Date(System.currentTimeMillis()));}
public void testMinuteAfter () { Date now = stringToDate("2012-12-22 11:59:59.999PM"); Date then = minuteAfter(now); assertEquals("2012-12-23 12:00:00.000AM", dateToString(then));}
public class PirateShipTest { @Test(dataProvider = "cannons") public void testFireCannonDepletesAmmunition(int ballsToLoad, int ballsToFire, int expectedRemaining) { PirateShip ship = new PirateShip("The Black Pearl"); ship.loadCannons(ballsToLoad); for (int i = 0; i < ballsToFire; i++) { ship.fireCannon(); } assertEquals(ship.getBallsRemaining(), expectedRemaining); } @DataProvider(name = "cannons") public Object[][] getShipSidesAndAmmunition() { // Each 1-D array represents a single execution of a @Test that // refers to this provider. The elements in the array represent // parameters to the test call. return new Object[] { {5, 1, 4}, {5, 5, 0}, {5, 0, 5} }; }}
<suite name="PirateShip suite" parallel="methods" thread-count="2">
@Test(expectedExceptions = { NoAmmunitionException.class })public void testFireCannonEmptyThrowsNoAmmunitionException() { PirateShip ship = new PirateShip("The Black Pearl"); ship.fireCannon();}