From 7c9d3c4dd8a5d2f512d607e8cce0fd55d24f82ef Mon Sep 17 00:00:00 2001 From: avinash-anand Date: Thu, 5 May 2016 13:25:35 +0100 Subject: [PATCH] ATED-1888 - added random and batch generator for AgentBusinessUtrs --- .../scala/uk/gov/hmrc/domain/Generator.scala | 22 ++++++++++++++++++- .../uk/gov/hmrc/domain/GeneratorSpec.scala | 13 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/scala/uk/gov/hmrc/domain/Generator.scala b/src/main/scala/uk/gov/hmrc/domain/Generator.scala index 01b852d..31322c9 100644 --- a/src/main/scala/uk/gov/hmrc/domain/Generator.scala +++ b/src/main/scala/uk/gov/hmrc/domain/Generator.scala @@ -30,7 +30,7 @@ class Generator(random: Random = new Random) extends Modulus23Check { } def atedUtrBatch(amountToGenerate: Int): List[AtedUtr] = { - require(amountToGenerate <= 900000, throw new IllegalArgumentException("Can't generate more than 9000000 unique AtedUtrs, specify a smaller value for amount")) + require(amountToGenerate <= 900000, throw new IllegalArgumentException("Can't generate more than 900000 unique AtedUtrs, specify a smaller value for amount")) val atedUtrs: ListBuffer[AtedUtr] = ListBuffer() var start = 100000 for (a <- 0 until amountToGenerate) { @@ -49,4 +49,24 @@ class Generator(random: Random = new Random) extends Modulus23Check { AtedUtr(f"X${checkCharacter}AT00000$suffix") } + def nextAgentBusinessUtr: AgentBusinessUtr = { + val suffix = f"${random.nextInt(1000000)}%07d" + val weighting = s"ARN$suffix" + val checkCharacter = calculateCheckCharacter(weighting) + AgentBusinessUtr(f"${checkCharacter}ARN$suffix") + } + + def agentBusinessUtrBatch(amountToGenerate: Int): List[AgentBusinessUtr] = { + require(amountToGenerate <= 9999999, throw new IllegalArgumentException("Can't generate more than 9999999 unique AgentBusinessUtr, specify a smaller value for amount")) + val agentBusinessUtrs: ListBuffer[AgentBusinessUtr] = ListBuffer() + var start = 0 + for (a <- 0 until amountToGenerate) { + val stringToWeight = f"ARN$start%07d" + val checkChar = calculateCheckCharacter(stringToWeight) + agentBusinessUtrs.++=(Seq(AgentBusinessUtr(s"$checkChar$stringToWeight"))) + start = start + 1 + } + agentBusinessUtrs.toList + } + } diff --git a/src/test/scala/uk/gov/hmrc/domain/GeneratorSpec.scala b/src/test/scala/uk/gov/hmrc/domain/GeneratorSpec.scala index 806e124..f6c230d 100644 --- a/src/test/scala/uk/gov/hmrc/domain/GeneratorSpec.scala +++ b/src/test/scala/uk/gov/hmrc/domain/GeneratorSpec.scala @@ -40,4 +40,17 @@ class GeneratorSpec extends WordSpec with Checkers { } } + + "AgentBusinessUtr Generation" should { + + "generate valid AgentBusinessUtr for all random seeds" in { + check(Prop.forAll { (seed: Int) => AgentBusinessUtr.isValid(new Generator(seed).nextAgentBusinessUtr.utr)}) + } + + "generate a batch of unique AgentBusinessUtr" in { + val agentBusinessUtrs = new Generator().agentBusinessUtrBatch(100000) + assert(agentBusinessUtrs.distinct.length == agentBusinessUtrs.length) + } + + } }