1
- package hmda .publication .reports
1
+ package hmda .publication .reports . util
2
2
3
- import akka .NotUsed
4
- import akka .actor .ActorSystem
5
- import akka .stream .ActorMaterializer
6
- import akka .stream .scaladsl .Source
7
- import hmda .model .fi .lar .{ LarGenerators , LoanApplicationRegister }
8
3
import hmda .model .publication .reports .ActionTakenTypeEnum .{ ApplicationReceived , LoansOriginated }
9
- import hmda .model .publication .reports .{ EthnicityBorrowerCharacteristic , EthnicityCharacteristic }
10
4
import hmda .model .publication .reports .EthnicityEnum ._
5
+ import hmda .model .publication .reports .{ EthnicityBorrowerCharacteristic , EthnicityCharacteristic }
11
6
import hmda .publication .reports .util .DispositionType .{ OriginatedDisp , ReceivedDisp }
12
7
import hmda .publication .reports .util .EthnicityUtil ._
13
- import hmda .query .model .filing .LoanApplicationRegisterQuery
14
- import hmda .query .repository .filing .LarConverter ._
15
8
import hmda .util .SourceUtils
16
9
import org .scalacheck .Gen
17
10
import org .scalatest .{ AsyncWordSpec , MustMatchers }
18
11
19
- class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators with SourceUtils {
20
-
21
- implicit val system = ActorSystem ()
22
- implicit val ec = system.dispatcher
23
- implicit val materializer = ActorMaterializer ()
24
-
25
- def larCollection (transformation : (LoanApplicationRegister => LoanApplicationRegister )): List [LoanApplicationRegister ] = {
26
- lar100ListGen.sample.get.map(transformation)
27
- }
28
-
29
- def source (lars : List [LoanApplicationRegister ]): Source [LoanApplicationRegisterQuery , NotUsed ] = Source
30
- .fromIterator(() => lars.toIterator)
31
- .map(lar => toLoanApplicationRegisterQuery(lar))
12
+ class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with SourceUtils with ApplicantSpecUtil {
32
13
33
14
" 'Hispanic or Latino' ethnicity filter" must {
34
15
" include applications that meet 'Hispanic or Latino' criteria" in {
35
16
def coAppEthnicity = Gen .oneOf(1 , 3 , 4 , 5 ).sample.get
36
- val lars = larCollection { lar =>
37
- val applicant = lar.applicant.copy(ethnicity = 1 , coEthnicity = coAppEthnicity)
38
- lar.copy(applicant = applicant)
39
- }
17
+ val lars = larCollectionWithApplicant(_.copy(ethnicity = 1 , coEthnicity = coAppEthnicity))
40
18
val latinoLars = filterEthnicity(source(lars), HispanicOrLatino )
41
19
count(latinoLars).map(_ mustBe 100 )
42
20
}
43
21
" exclude applications where applicant does not meet criteria" in {
44
- val larsExcludedByApplicant = larCollection { lar =>
45
- val applicant = lar.applicant.copy(ethnicity = 2 , coEthnicity = 3 )
46
- lar.copy(applicant = applicant)
47
- }
22
+ val larsExcludedByApplicant = larCollectionWithApplicant(_.copy(ethnicity = 2 , coEthnicity = 3 ))
48
23
val nonLatinoLars1 = filterEthnicity(source(larsExcludedByApplicant), HispanicOrLatino )
49
24
count(nonLatinoLars1).map(_ mustBe 0 )
50
25
}
51
26
" exclude applications where coApplicant does not meet criteria" in {
52
- val larsExcludedByCoApplicant = larCollection { lar =>
53
- val applicant = lar.applicant.copy(ethnicity = 1 , coEthnicity = 2 )
54
- lar.copy(applicant = applicant)
55
- }
27
+ val larsExcludedByCoApplicant = larCollectionWithApplicant(_.copy(ethnicity = 1 , coEthnicity = 2 ))
56
28
val nonLatinoLars2 = filterEthnicity(source(larsExcludedByCoApplicant), HispanicOrLatino )
57
29
count(nonLatinoLars2).map(_ mustBe 0 )
58
30
}
@@ -61,27 +33,17 @@ class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerato
61
33
" 'Not Hispanic or Latino' ethnicity filter" must {
62
34
" include applications that meet 'Not Hispanic/Latino' criteria" in {
63
35
def coAppEthnicity = Gen .oneOf(2 , 3 , 4 , 5 ).sample.get
64
- val lars = larCollection { lar =>
65
- val applicant = lar.applicant.copy(ethnicity = 2 , coEthnicity = coAppEthnicity)
66
- lar.copy(applicant = applicant)
67
- }
68
-
36
+ val lars = larCollectionWithApplicant(_.copy(ethnicity = 2 , coEthnicity = coAppEthnicity))
69
37
val nonLatinoLars = filterEthnicity(source(lars), NotHispanicOrLatino )
70
38
count(nonLatinoLars).map(_ mustBe 100 )
71
39
}
72
40
" exclude applications where applicant does not meet criteria" in {
73
- val larsExcludedByApplicant = larCollection { lar =>
74
- val applicant = lar.applicant.copy(ethnicity = 1 , coEthnicity = 3 )
75
- lar.copy(applicant = applicant)
76
- }
41
+ val larsExcludedByApplicant = larCollectionWithApplicant(_.copy(ethnicity = 1 , coEthnicity = 3 ))
77
42
val latinoLars1 = filterEthnicity(source(larsExcludedByApplicant), NotHispanicOrLatino )
78
43
count(latinoLars1).map(_ mustBe 0 )
79
44
}
80
45
" exclude applications where coApplicant does not meet criteria" in {
81
- val larsExcludedByCoApplicant = larCollection { lar =>
82
- val applicant = lar.applicant.copy(ethnicity = 2 , coEthnicity = 1 )
83
- lar.copy(applicant = applicant)
84
- }
46
+ val larsExcludedByCoApplicant = larCollectionWithApplicant(_.copy(ethnicity = 2 , coEthnicity = 1 ))
85
47
val latinoLars2 = filterEthnicity(source(larsExcludedByCoApplicant), NotHispanicOrLatino )
86
48
count(latinoLars2).map(_ mustBe 0 )
87
49
}
@@ -90,48 +52,35 @@ class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerato
90
52
" 'Not Available' ethnicity filter" must {
91
53
" include applications that meet 'Not Available' criteria" in {
92
54
def appEthnicity = Gen .oneOf(3 , 4 ).sample.get
93
- val lars = larCollection { lar =>
94
- val applicant = lar.applicant.copy(ethnicity = appEthnicity)
95
- lar.copy(applicant = applicant)
96
- }
55
+ val lars = larCollectionWithApplicant(_.copy(ethnicity = appEthnicity))
97
56
98
57
val notAvailableLars = filterEthnicity(source(lars), NotAvailable )
99
58
count(notAvailableLars).map(_ mustBe 100 )
100
59
}
101
60
" exclude applications that do not meet 'Not Available' criteria" in {
102
61
def appEthnicity = Gen .oneOf(1 , 2 ).sample.get
103
- val larsExcludedByApplicant = larCollection { lar =>
104
- val applicant = lar.applicant.copy(ethnicity = appEthnicity)
105
- lar.copy(applicant = applicant)
106
- }
62
+ val larsExcludedByApplicant = larCollectionWithApplicant(_.copy(ethnicity = appEthnicity))
107
63
val lars = filterEthnicity(source(larsExcludedByApplicant), NotAvailable )
108
64
count(lars).map(_ mustBe 0 )
109
65
}
110
66
}
111
67
112
68
" 'Joint' ethnicity filter" must {
113
69
" include applications with hispanic applicant and non-hispanic coApplicant" in {
114
- val lars1 = larCollection { lar =>
115
- val applicant = lar.applicant.copy(ethnicity = 1 , coEthnicity = 2 )
116
- lar.copy(applicant = applicant)
117
- }
70
+ val lars1 = larCollectionWithApplicant(_.copy(ethnicity = 1 , coEthnicity = 2 ))
118
71
val jointLars1 = filterEthnicity(source(lars1), Joint )
119
72
count(jointLars1).map(_ mustBe 100 )
120
73
}
121
74
" include applications with non-hispanic applicant and hispanic coApplicant" in {
122
- val lars2 = larCollection { lar =>
123
- val applicant = lar.applicant.copy(ethnicity = 2 , coEthnicity = 1 )
124
- lar.copy(applicant = applicant)
125
- }
75
+ val lars2 = larCollectionWithApplicant(_.copy(ethnicity = 2 , coEthnicity = 1 ))
126
76
val jointLars2 = filterEthnicity(source(lars2), Joint )
127
77
count(jointLars2).map(_ mustBe 100 )
128
78
}
129
79
" exclude applications that do not meet 'Joint' criteria" in {
130
80
def ethnicity = Gen .oneOf(1 , 2 ).sample.get
131
- val larsWithSameEthnicity = larCollection { lar =>
81
+ val larsWithSameEthnicity = larCollectionWithApplicant { app =>
132
82
val eth = ethnicity
133
- val applicant = lar.applicant.copy(ethnicity = eth, coEthnicity = eth)
134
- lar.copy(applicant = applicant)
83
+ app.copy(ethnicity = eth, coEthnicity = eth)
135
84
}
136
85
val lars = filterEthnicity(source(larsWithSameEthnicity), Joint )
137
86
count(lars).map(_ mustBe 0 )
0 commit comments