-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator_test.go
83 lines (60 loc) · 2.01 KB
/
generator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package drivinglicence_test
import (
"drivinglicence"
"drivinglicence/mock"
"github.com/stretchr/testify/suite"
"testing"
)
type DrivingLicenceSuite struct {
applicant *mock.FakeApplicant
logger *mock.FakeLogger
randomNumbersGenerator *mock.FakeRandomNumbersGenerator
lg drivinglicence.NumberGenerator
suite.Suite
}
func TestDrivingLicenceSuite(t *testing.T) {
suite.Run(t, new(DrivingLicenceSuite))
}
func (s *DrivingLicenceSuite) SetupTest() {
s.applicant = &mock.FakeApplicant{}
s.logger = &mock.FakeLogger{}
s.randomNumbersGenerator = &mock.FakeRandomNumbersGenerator{}
s.lg = drivinglicence.NewNumberGenerator(s.logger, s.randomNumbersGenerator)
}
func (s *DrivingLicenceSuite) TestUnderageApplicant() {
s.applicant.HoldsLicenceReturns(false)
s.applicant.IsOver17Returns(false)
_, err := s.lg.Generate(s.applicant)
s.Error(err)
s.Contains(err.Error(), "Underaged")
s.Equal(1, s.logger.LogStuffCallCount())
s.Contains(s.logger.LogStuffArgsForCall(0), "Underaged")
}
func (s *DrivingLicenceSuite) TestNoSecondLicence() {
s.applicant.HoldsLicenceReturns(true)
_, err := s.lg.Generate(s.applicant)
s.Error(err)
s.Contains(err.Error(), "Duplicate")
s.Equal(1, s.logger.LogStuffCallCount())
s.Contains(s.logger.LogStuffArgsForCall(0), "Duplicate")
}
func (s *DrivingLicenceSuite) TestLicenceGeneration() {
s.applicant.HoldsLicenceReturns(false)
s.applicant.IsOver17Returns(true)
s.applicant.GetInitialsReturns("MDB")
s.applicant.GetDOBReturns("23082011")
s.randomNumbersGenerator.GetRandomNumbersReturns("00000")
ln, err := s.lg.Generate(s.applicant)
s.NoError(err)
s.Equal("MDB2308201100000", ln)
}
func (s *DrivingLicenceSuite) TestLicenceGenerationShorterInitials() {
s.applicant.HoldsLicenceReturns(false)
s.applicant.IsOver17Returns(true)
s.applicant.GetInitialsReturns("MB")
s.applicant.GetDOBReturns("23082011")
s.randomNumbersGenerator.GetRandomNumbersReturns("000000")
ln, err := s.lg.Generate(s.applicant)
s.NoError(err)
s.Equal("MB23082011000000", ln)
}