0

I tried

  val arbLong: Gen[Long] = {
    Gen.frequency((20, Arbitrary.arbLong), (20, null)).sample.get.arbitrary
  }


  "arbLong" should "be able to generate null values" in {
    forAll(arbLong) { (generatedLong: Long) =>
      println(generatedLong)
    }

  }

so it does generate a null for longs, however I get NullPointerException most probably because of Long cannot hold null what is the proper way to use an arbitrary long generator which includes nulls?

Jas
  • 14,493
  • 27
  • 97
  • 148

1 Answers1

2

Scala's Long cannot be null (Pass null to a method expects Long). If you want to represent Longs which may or may not be present then use either java.lang.Long:

val arbLong: Gen[java.lang.Long] = {
  Gen.frequency((20, Arbitrary.arbLong), (20, null)).sample.get.arbitrary
}

or Option[Long] (see Generate Option[T] in ScalaCheck).

Community
  • 1
  • 1
Joe
  • 29,416
  • 12
  • 68
  • 88