Skip to content

Commit 2d6658e

Browse files
committed
Test msaReport method of ReportUtil
1 parent 36b690e commit 2d6658e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

publication/src/main/scala/hmda/publication/reports/util/ReportUtil.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import scala.concurrent.Future
1818
object ReportUtil extends SourceUtils {
1919

2020
def msaReport(fipsCode: String): MSAReport = {
21-
val cbsa = CbsaLookup.values.find(x => x.cbsa == fipsCode).getOrElse(Cbsa())
22-
val stateFips = cbsa.key.substring(0, 2)
23-
val state = StateAbrvLookup.values.find(s => s.state == stateFips).getOrElse(StateAbrv("", "", ""))
24-
MSAReport(fipsCode, CbsaLookup.nameFor(fipsCode), state.stateAbrv, state.stateName)
21+
CbsaLookup.values.find(x => x.cbsa == fipsCode) match {
22+
case Some(cbsa) =>
23+
val stateFips = cbsa.key.substring(0, 2)
24+
val state = StateAbrvLookup.values.find(s => s.state == stateFips).getOrElse(StateAbrv("", "", ""))
25+
MSAReport(fipsCode, CbsaLookup.nameFor(fipsCode), state.stateAbrv, state.stateName)
26+
case None => MSAReport("", "", "", "")
27+
}
2528
}
2629

2730
def calculateMedianIncomeIntervals(fipsCode: Int): Array[Double] = {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package hmda.publication.reports.util
2+
3+
import hmda.model.publication.reports.MSAReport
4+
import hmda.publication.reports.util.ReportUtil._
5+
import org.scalatest.{ AsyncWordSpec, MustMatchers }
6+
7+
class ReportUtilSpec extends AsyncWordSpec with MustMatchers {
8+
9+
"msaReport" must {
10+
"get MSA info for given fips code and return MSAReport object" in {
11+
msaReport("10380") mustBe MSAReport("10380", "Aguadilla-Isabela, PR", "PR", "Puerto Rico")
12+
msaReport("26980") mustBe MSAReport("26980", "Iowa City, IA", "IA", "Iowa")
13+
msaReport("41100") mustBe MSAReport("41100", "St. George, UT", "UT", "Utah")
14+
}
15+
16+
"Return empty MSAReport if fips code is invalid" in {
17+
msaReport("bogus") mustBe MSAReport("", "", "", "")
18+
}
19+
}
20+
21+
}

0 commit comments

Comments
 (0)