Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.64 KB | None | 0 0
  1. func TestCanCountTheTweetsSentByAnUser(t *testing.T) {
  2.  
  3.     // Initialization
  4.     service.InitializeService()
  5.  
  6.     var tweet, secondTweet, thirdTweet *domain.Tweet
  7.  
  8.     user := "grupoesfera"
  9.     anotherUser := "nick"
  10.     text := "This is my first tweet"
  11.     secondText := "This is my second tweet"
  12.  
  13.     tweet = domain.NewTweet(user, text)
  14.     secondTweet = domain.NewTweet(user, secondText)
  15.     thirdTweet = domain.NewTweet(anotherUser, text)
  16.  
  17.     service.PublishTweet(tweet)
  18.     service.PublishTweet(secondTweet)
  19.     service.PublishTweet(thirdTweet)
  20.  
  21.     // Operation
  22.     count := service.CountTweetsByUser(user)
  23.  
  24.     // Validation
  25.     if count != 2 {
  26.         t.Errorf("Expected count is 2 but was %d", count)
  27.     }
  28.  
  29. }
  30.  
  31. func TestCanRetrieveTheTweetsSentByAnUser(t *testing.T) {
  32.  
  33.     // Initialization
  34.     service.InitializeService()
  35.  
  36.     var tweet, secondTweet, thirdTweet *domain.Tweet
  37.  
  38.     user := "grupoesfera"
  39.     anotherUser := "nick"
  40.     text := "This is my first tweet"
  41.     secondText := "This is my second tweet"
  42.  
  43.     tweet = domain.NewTweet(user, text)
  44.     secondTweet = domain.NewTweet(user, secondText)
  45.     thirdTweet = domain.NewTweet(anotherUser, text)
  46.  
  47.     firstId, _ := service.PublishTweet(tweet)
  48.     secondId, _ := service.PublishTweet(secondTweet)
  49.     service.PublishTweet(thirdTweet)
  50.  
  51.     // Operation
  52.     tweets := service.GetTweetsByUser(user)
  53.  
  54.     // Validation
  55.     if len(tweets) != 2 {
  56.  
  57.         t.Errorf("Expected size is 2 but was %d", len(tweets))
  58.         return
  59.     }
  60.  
  61.     firstPublishedTweet := tweets[0]
  62.     secondPublishedTweet := tweets[1]
  63.  
  64.     if !isValidTweet(t, firstPublishedTweet, firstId, user, text) {
  65.         return
  66.     }
  67.  
  68.     if !isValidTweet(t, secondPublishedTweet, secondId, user, secondText) {
  69.         return
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement