@Test public void testProcessTransaction() { User user = newUserWithBalance(LOW_BALANCE_THRESHOLD.plus(dollars(2)); transactionProcessor.processTransaction( user, new Transaction("Pile of Beanie Babies", dollars(3))); assertContains("You bought a Pile of Beanie Babies", ui.getText()); assertEquals(1, user.getEmails().size()); assertEquals("Your balance is low", user.getEmails().get(0).getSubject()); }
@Test public void testProcessTransaction_displaysNotification() { transactionProcessor.processTransaction( new User(), new Transaction("Pile of Beanie Babies")); assertContains("You bought a Pile of Beanie Babies", ui.getText()); } @Test public void testProcessTransaction_sendsEmailWhenBalanceIsLow() { User user = newUserWithBalance(LOW_BALANCE_THRESHOLD.plus(dollars(2)); transactionProcessor.processTransaction( user, new Transaction(dollars(3))); assertEquals(1, user.getEmails().size()); assertEquals("Your balance is low", user.getEmails().get(0).getSubject()); }
class LinkGeneratorTest(googletest.TestCase): def setUp(self): self.generator = link_generator.LinkGenerator() def testGetLinkFromIDs(self): expected = ('https://frontend.google.com/advancedSearchResults?' 's.op=ALL&s.r0.field=ID&s.r0.val=1288585+1310696+1346270+') actual = self.generator.GetLinkFromIDs(set((1346270, 1310696, 1288585))) self.assertEqual(expected, actual)
import urllib class LinkGenerator(object): _URL = ( 'https://frontend.google.com/advancedSearchResults?' 's.op=ALL&s.r0.field=ID&s.r0.val=') def GetLinkFromIDs(self, ids): result = [] for id in sorted(ids): result.append('%s ' % id) return self._URL + urllib.quote_plus(''.join(result))