GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch feature/payments-resource-impl... (bdb051)
by Victor Hugo
02:14
created

mollie.TestNewCurrency   C

Complexity

Conditions 8

Size

Total Lines 73
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 54
nop 1
dl 0
loc 73
rs 6.6387
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
package mollie
2
3
import (
4
	"reflect"
5
	"testing"
6
)
7
8
func TestNewCurrency(t *testing.T) {
9
	type args struct {
10
		code  string
11
		value string
12
	}
13
	tests := []struct {
14
		name    string
15
		args    args
16
		want    Currency
17
		wantErr bool
18
		err     error
19
	}{
20
		{
21
			name: "test a currency is correctly instantiated",
22
			args: args{
23
				code:  "MXN",
24
				value: "1000.00",
25
			},
26
			want: Currency{
27
				CurrencyCode: "MXN",
28
				Value:        "1000.00",
29
			},
30
			wantErr: false,
31
			err:     nil,
32
		},
33
		{
34
			name: "test invalid alpha3 code returns error",
35
			args: args{
36
				code:  "Mexican peso",
37
				value: "1000.00",
38
			},
39
			want:    Currency{},
40
			wantErr: true,
41
			err:     errInvalidISO4217Code,
42
		},
43
		{
44
			name: "test an empty currency code defaults to EUR",
45
			args: args{
46
				code:  "",
47
				value: "1000.00",
48
			},
49
			want: Currency{
50
				CurrencyCode: "EUR",
51
				Value:        "1000.00",
52
			},
53
			wantErr: false,
54
			err:     nil,
55
		},
56
		{
57
			name: "test a string containing a space as currency code defaults to EUR",
58
			args: args{
59
				code:  " ",
60
				value: "1000.00",
61
			},
62
			want: Currency{
63
				CurrencyCode: "EUR",
64
				Value:        "1000.00",
65
			},
66
			wantErr: false,
67
			err:     nil,
68
		},
69
	}
70
71
	for _, tt := range tests {
72
		t.Run(tt.name, func(t *testing.T) {
73
			got, err := NewCurrency(tt.args.code, tt.args.value)
74
			if tt.wantErr && err != nil {
75
				if tt.err.Error() != err.Error() {
76
					t.Errorf("error mismatch, got: %v | want %v", err, tt.err)
77
				}
78
			} else {
79
				if !reflect.DeepEqual(got, tt.want) || err != nil {
80
					t.Errorf("expectation mismatch: got %v | want: %v", got, tt.want)
81
				}
82
			}
83
		})
84
	}
85
}
86