| Conditions | 5 |
| Total Lines | 58 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | //////////////////////////////////////////////////////////////////////////////// |
||
| 20 | func TestEmailStrategy_Write(t *testing.T) { |
||
| 21 | mockCtrl := gomock.NewController(t) |
||
| 22 | defer mockCtrl.Finish() |
||
| 23 | type args struct { |
||
| 24 | p []byte |
||
| 25 | } |
||
| 26 | |||
| 27 | from := "[email protected]" |
||
| 28 | to := []string{"<[email protected]>"} |
||
| 29 | |||
| 30 | msg := gomail.NewMessage() |
||
| 31 | msg.SetHeader("From", "Example <[email protected]>") |
||
| 32 | msg.SetHeader("Bcc", to...) |
||
| 33 | msg.SetHeader("Subject", "Debug message") |
||
| 34 | |||
| 35 | mockSendCloser := mocks.NewMockSendCloser(mockCtrl) |
||
| 36 | mockSendCloser.EXPECT().Send(from, []string{"[email protected]"}, msg).Return(nil).AnyTimes() |
||
| 37 | |||
| 38 | sender := mailSender.Create(&mailSender.Sender{ |
||
| 39 | Channel: make(chan mailSender.Message, 1), |
||
| 40 | Closer: mockSendCloser, |
||
| 41 | }) |
||
| 42 | |||
| 43 | tpl, _ := template.New("test").Parse("<pre><code>{{ .Data }}</code></pre>") |
||
| 44 | |||
| 45 | strategy := Get(sender, msg, tpl) |
||
| 46 | stack := debug.Stack() |
||
| 47 | tests := []struct { |
||
| 48 | name string |
||
| 49 | fields *Strategy |
||
| 50 | args args |
||
| 51 | wantN int |
||
| 52 | wantErr bool |
||
| 53 | }{ |
||
| 54 | { |
||
| 55 | fields: strategy.(*Strategy), |
||
| 56 | args: args{ |
||
| 57 | p: stack, |
||
| 58 | }, |
||
| 59 | wantN: len(stack), |
||
| 60 | wantErr: false, |
||
| 61 | }, |
||
| 62 | } |
||
| 63 | for _, tt := range tests { |
||
| 64 | t.Run(tt.name, func(t *testing.T) { |
||
| 65 | s := &Strategy{ |
||
| 66 | Writer: tt.fields.Writer, |
||
| 67 | sender: tt.fields.sender, |
||
| 68 | Message: tt.fields.Message, |
||
| 69 | Template: tt.fields.Template, |
||
| 70 | } |
||
| 71 | gotN, err := s.Write(tt.args.p) |
||
| 72 | if (err != nil) != tt.wantErr { |
||
| 73 | t.Errorf("EmailStrategy.Write() error = %v, wantErr %v", err, tt.wantErr) |
||
| 74 | return |
||
| 75 | } |
||
| 76 | if gotN != tt.wantN { |
||
| 77 | t.Errorf("EmailWrite() = %v, want %v", gotN, tt.wantN) |
||
| 78 | } |
||
| 82 |