Skip to content

Commit d1b3b09

Browse files
committed
Share useful spec methods in ApplicantSpecUtil
1 parent b727903 commit d1b3b09

File tree

4 files changed

+57
-130
lines changed

4 files changed

+57
-130
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package hmda.publication.reports.util
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.{ Applicant, LarGenerators, LoanApplicationRegister }
8+
import hmda.query.model.filing.LoanApplicationRegisterQuery
9+
import hmda.query.repository.filing.LarConverter._
10+
11+
trait ApplicantSpecUtil extends LarGenerators {
12+
13+
implicit val system = ActorSystem()
14+
implicit val ec = system.dispatcher
15+
implicit val materializer = ActorMaterializer()
16+
17+
def larCollectionWithApplicant(transformation: (Applicant => Applicant)): List[LoanApplicationRegister] = {
18+
lar100ListGen.sample.get.map { lar =>
19+
val newApplicant = transformation(lar.applicant)
20+
lar.copy(applicant = newApplicant)
21+
}
22+
}
23+
24+
def source(lars: List[LoanApplicationRegister]): Source[LoanApplicationRegisterQuery, NotUsed] = Source
25+
.fromIterator(() => lars.toIterator)
26+
.map(lar => toLoanApplicationRegisterQuery(lar))
27+
28+
}

publication/src/test/scala/hmda/publication/reports/util/EthnicityUtilSpec.scala

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,30 @@
1-
package hmda.publication.reports
1+
package hmda.publication.reports.util
22

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 }
83
import hmda.model.publication.reports.ActionTakenTypeEnum.{ ApplicationReceived, LoansOriginated }
9-
import hmda.model.publication.reports.{ EthnicityBorrowerCharacteristic, EthnicityCharacteristic }
104
import hmda.model.publication.reports.EthnicityEnum._
5+
import hmda.model.publication.reports.{ EthnicityBorrowerCharacteristic, EthnicityCharacteristic }
116
import hmda.publication.reports.util.DispositionType.{ OriginatedDisp, ReceivedDisp }
127
import hmda.publication.reports.util.EthnicityUtil._
13-
import hmda.query.model.filing.LoanApplicationRegisterQuery
14-
import hmda.query.repository.filing.LarConverter._
158
import hmda.util.SourceUtils
169
import org.scalacheck.Gen
1710
import org.scalatest.{ AsyncWordSpec, MustMatchers }
1811

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 {
3213

3314
"'Hispanic or Latino' ethnicity filter" must {
3415
"include applications that meet 'Hispanic or Latino' criteria" in {
3516
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))
4018
val latinoLars = filterEthnicity(source(lars), HispanicOrLatino)
4119
count(latinoLars).map(_ mustBe 100)
4220
}
4321
"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))
4823
val nonLatinoLars1 = filterEthnicity(source(larsExcludedByApplicant), HispanicOrLatino)
4924
count(nonLatinoLars1).map(_ mustBe 0)
5025
}
5126
"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))
5628
val nonLatinoLars2 = filterEthnicity(source(larsExcludedByCoApplicant), HispanicOrLatino)
5729
count(nonLatinoLars2).map(_ mustBe 0)
5830
}
@@ -61,27 +33,17 @@ class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerato
6133
"'Not Hispanic or Latino' ethnicity filter" must {
6234
"include applications that meet 'Not Hispanic/Latino' criteria" in {
6335
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))
6937
val nonLatinoLars = filterEthnicity(source(lars), NotHispanicOrLatino)
7038
count(nonLatinoLars).map(_ mustBe 100)
7139
}
7240
"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))
7742
val latinoLars1 = filterEthnicity(source(larsExcludedByApplicant), NotHispanicOrLatino)
7843
count(latinoLars1).map(_ mustBe 0)
7944
}
8045
"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))
8547
val latinoLars2 = filterEthnicity(source(larsExcludedByCoApplicant), NotHispanicOrLatino)
8648
count(latinoLars2).map(_ mustBe 0)
8749
}
@@ -90,48 +52,35 @@ class EthnicityUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerato
9052
"'Not Available' ethnicity filter" must {
9153
"include applications that meet 'Not Available' criteria" in {
9254
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))
9756

9857
val notAvailableLars = filterEthnicity(source(lars), NotAvailable)
9958
count(notAvailableLars).map(_ mustBe 100)
10059
}
10160
"exclude applications that do not meet 'Not Available' criteria" in {
10261
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))
10763
val lars = filterEthnicity(source(larsExcludedByApplicant), NotAvailable)
10864
count(lars).map(_ mustBe 0)
10965
}
11066
}
11167

11268
"'Joint' ethnicity filter" must {
11369
"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))
11871
val jointLars1 = filterEthnicity(source(lars1), Joint)
11972
count(jointLars1).map(_ mustBe 100)
12073
}
12174
"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))
12676
val jointLars2 = filterEthnicity(source(lars2), Joint)
12777
count(jointLars2).map(_ mustBe 100)
12878
}
12979
"exclude applications that do not meet 'Joint' criteria" in {
13080
def ethnicity = Gen.oneOf(1, 2).sample.get
131-
val larsWithSameEthnicity = larCollection { lar =>
81+
val larsWithSameEthnicity = larCollectionWithApplicant { app =>
13282
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)
13584
}
13685
val lars = filterEthnicity(source(larsWithSameEthnicity), Joint)
13786
count(lars).map(_ mustBe 0)

publication/src/test/scala/hmda/publication/reports/util/MinorityStatusUtilSpec.scala

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
1-
package hmda.publication.reports
1+
package hmda.publication.reports.util
22

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 }
83
import hmda.model.publication.reports.ActionTakenTypeEnum.{ ApplicationReceived, LoansOriginated }
9-
import hmda.model.publication.reports.{ MinorityStatusBorrowerCharacteristic, MinorityStatusCharacteristic }
104
import hmda.model.publication.reports.MinorityStatusEnum._
5+
import hmda.model.publication.reports.{ MinorityStatusBorrowerCharacteristic, MinorityStatusCharacteristic }
116
import hmda.publication.reports.util.DispositionType.{ OriginatedDisp, ReceivedDisp }
127
import hmda.publication.reports.util.MinorityStatusUtil._
13-
import hmda.query.model.filing.LoanApplicationRegisterQuery
14-
import hmda.query.repository.filing.LarConverter._
158
import hmda.util.SourceUtils
169
import org.scalacheck.Gen
1710
import org.scalatest.{ AsyncWordSpec, MustMatchers }
1811

19-
class MinorityStatusUtilSpec 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 MinorityStatusUtilSpec extends AsyncWordSpec with MustMatchers with SourceUtils with ApplicantSpecUtil {
3213

3314
"'White Non-Hispanic' minority status filter" must {
3415
"include applications that meet 'White Non-Hispanic' criteria" in {
35-
val lars = larCollection { lar =>
36-
val applicant = lar.applicant.copy(ethnicity = 2, race1 = 5)
37-
lar.copy(applicant = applicant)
38-
}
39-
16+
val lars = larCollectionWithApplicant(_.copy(ethnicity = 2, race1 = 5))
4017
val nonHispanicLars = filterMinorityStatus(source(lars), WhiteNonHispanic)
4118
count(nonHispanicLars).map(_ mustBe 100)
4219
}
4320
"exclude applications that do not meet 'White Non-Hispanic' criteria" in {
4421
def excludedRace = Gen.oneOf(1, 2, 3, 4, 6, 7).sample.get
4522
def excludedEthnicity = Gen.oneOf(1, 3, 4).sample.get
46-
val excludedLars = larCollection { lar =>
47-
val applicant = lar.applicant.copy(ethnicity = excludedEthnicity, race1 = excludedRace)
48-
lar.copy(applicant = applicant)
49-
}
23+
24+
val excludedLars = larCollectionWithApplicant(_.copy(ethnicity = excludedEthnicity, race1 = excludedRace))
5025
val excluded = filterMinorityStatus(source(excludedLars), WhiteNonHispanic)
5126
count(excluded).map(_ mustBe 0)
5227
}
@@ -56,21 +31,17 @@ class MinorityStatusUtilSpec extends AsyncWordSpec with MustMatchers with LarGen
5631
"include applications that meet 'Other, Including Hispanic' criteria" in {
5732
def appRace1 = Gen.oneOf(1, 2, 3, 4).sample.get
5833
def appRace2to5 = Gen.oneOf("1", "2", "3", "4", "").sample.get
59-
val lars = larCollection { lar =>
60-
val applicant = lar.applicant.copy(ethnicity = 1, race1 = appRace1,
61-
race2 = appRace2to5, race3 = appRace2to5, race4 = appRace2to5, race5 = appRace2to5)
62-
lar.copy(applicant = applicant)
34+
val lars = larCollectionWithApplicant { app =>
35+
app.copy(ethnicity = 1, race1 = appRace1, race2 = appRace2to5,
36+
race3 = appRace2to5, race4 = appRace2to5, race5 = appRace2to5)
6337
}
6438

6539
val hispanicLars = filterMinorityStatus(source(lars), OtherIncludingHispanic)
6640
count(hispanicLars).map(_ mustBe 100)
6741
}
6842
"exclude applications that do not meet 'Other, Including Hispanic' criteria" in {
6943
def appEthnicity = Gen.oneOf(2, 3, 4).sample.get
70-
val excludedLars = larCollection { lar =>
71-
val applicant = lar.applicant.copy(ethnicity = appEthnicity, race1 = 5)
72-
lar.copy(applicant = applicant)
73-
}
44+
val excludedLars = larCollectionWithApplicant(_.copy(ethnicity = appEthnicity, race1 = 5))
7445
val lars = filterMinorityStatus(source(excludedLars), OtherIncludingHispanic)
7546
count(lars).map(_ mustBe 0)
7647
}

publication/src/test/scala/hmda/publication/reports/util/RaceUtilSpec.scala

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
1-
package hmda.publication.reports
1+
package hmda.publication.reports.util
22

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.{ Applicant, LarGenerators, LoanApplicationRegister }
3+
import hmda.model.fi.lar.Applicant
84
import hmda.model.publication.reports.ActionTakenTypeEnum.{ ApplicationReceived, LoansOriginated }
9-
import hmda.model.publication.reports.{ RaceBorrowerCharacteristic, RaceCharacteristic }
105
import hmda.model.publication.reports.RaceEnum._
6+
import hmda.model.publication.reports.{ RaceBorrowerCharacteristic, RaceCharacteristic }
117
import hmda.publication.reports.util.DispositionType.{ OriginatedDisp, ReceivedDisp }
128
import hmda.publication.reports.util.RaceUtil._
13-
import hmda.query.model.filing.LoanApplicationRegisterQuery
14-
import hmda.query.repository.filing.LarConverter._
159
import hmda.util.SourceUtils
1610
import org.scalacheck.Gen
1711
import org.scalatest.{ AsyncWordSpec, MustMatchers }
1812

19-
class RaceUtilSpec 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 larCollectionWithApplicant(transformation: (Applicant => Applicant)): List[LoanApplicationRegister] = {
26-
lar100ListGen.sample.get.map { lar =>
27-
val newApplicant = transformation(lar.applicant)
28-
lar.copy(applicant = newApplicant)
29-
}
30-
}
31-
32-
def source(lars: List[LoanApplicationRegister]): Source[LoanApplicationRegisterQuery, NotUsed] = Source
33-
.fromIterator(() => lars.toIterator)
34-
.map(lar => toLoanApplicationRegisterQuery(lar))
13+
class RaceUtilSpec extends AsyncWordSpec with MustMatchers with SourceUtils with ApplicantSpecUtil {
3514

3615
def nonWhiteRaceGen = Gen.oneOf("1", "2", "3", "4").sample.get
3716
def coApplicantNotWhite(app: Applicant) = {

0 commit comments

Comments
 (0)