From d4ba4d924744d95b9003d68f4314ce2f0910a1b0 Mon Sep 17 00:00:00 2001 From: Pavlo Tsipinio Date: Mon, 21 Aug 2023 15:08:28 +0300 Subject: [PATCH 1/3] updated scala. Added scala3 support --- .gitignore | 5 + .scalafmt.conf | 58 ++ build.sbt | 58 +- project/build.properties | 2 +- project/plugins.sbt | 13 +- src/main/scala/fabricator/Alphanumeric.scala | 43 +- src/main/scala/fabricator/Contact.scala | 55 +- src/main/scala/fabricator/Mobile.scala | 8 +- .../fabricator/entities/RelativeDate.scala | 22 +- .../fabricator/entities/UrlBuilder.scala | 61 +-- .../fabricator/AlphaNumericTestSuite.scala | 135 ++--- .../scala/fabricator/CalendarTestSuite.scala | 509 +++++++++++++----- .../scala/fabricator/ContactTestSuite.scala | 112 ++-- src/test/scala/fabricator/FileTestSuite.scala | 260 ++++----- .../scala/fabricator/FinanceTestSuite.scala | 36 +- .../scala/fabricator/InternetTestSuite.scala | 62 ++- .../scala/fabricator/LocationTestSuite.scala | 37 +- .../scala/fabricator/MobileTestSuite.scala | 5 +- .../scala/fabricator/WordsTestSuite.scala | 33 +- 19 files changed, 946 insertions(+), 568 deletions(-) create mode 100644 .scalafmt.conf diff --git a/.gitignore b/.gitignore index 17f17f8..139d768 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,8 @@ test-output/* project/project/ generatedFiles/ test-output/ +.bloop +.vscode/ +metals.sbt +.metals +.bsp \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..d685dde --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,58 @@ +version = "3.7.12" +runner.dialect = scala213 + +style = defaultWithAlign +maxColumn = 120 +align = most + +continuationIndent.defnSite = 2 +align.arrowEnumeratorGenerator = true +align.openParenCallSite = false +align.openParenDefnSite = false + +assumeStandardLibraryStripMargin = true +align.stripMargin = true + +danglingParentheses.defnSite = true +danglingParentheses.callSite = true +danglingParentheses.exclude = [class, trait, enum, def] + +docstrings.style = Asterisk +docstrings.wrap = "no" +docstrings.forceBlankLineBefore = true + +rewrite.rules = [RedundantBraces, RedundantParens, SortImports, PreferCurlyFors, SortModifiers] +rewrite.redundantBraces.includeUnitMethods = true +rewrite.redundantBraces.stringInterpolation = true +rewrite.redundantBraces.methodBodies = false + +rewrite.imports.sort = ascii +rewrite.imports.groups = [ + ["javax?\\..*"] + ["org\\..*"] + ["com\\..*"] + ["scala\\..*"] + ["io\\..*", "cats\\..*"] + ["scala\\.concurrent\\..*"] +] + +rewrite.sortModifiers { + order = [ + override + private + protected + final + sealed + abstract + lazy + implicit + ] +} + +rewrite.trailingCommas.style = "never" + +newlines.topLevelStatementBlankLines = [ + { + blanks { before = 1 } + } +] \ No newline at end of file diff --git a/build.sbt b/build.sbt index b324ba4..ef6abf9 100644 --- a/build.sbt +++ b/build.sbt @@ -1,18 +1,18 @@ import sbt.Keys._ -scalaVersion := "2.13.5" +scalaVersion := "2.13.11" -crossScalaVersions := Seq("2.12.10", "2.13.5") +crossScalaVersions := Seq("2.12.18", "2.13.11", "3.3.0") scalacOptions += "-target:jvm-1.8" name := "fabricator" -version := "2.1.9" +version := "2.2.0" organization := "com.github.azakordonets" -licenses +=("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html")) +licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html")) homepage := Some(url("https://github.com/azakordonets/fabricator")) @@ -23,25 +23,28 @@ publishMavenStyle := true publishTo := { val nexus = "https://oss.sonatype.org/" if (isSnapshot.value) - Some("snapshots" at nexus + "content/repositories/snapshots") + Some("snapshots" at nexus + "content/repositories/snapshots") else - Some("releases" at nexus + "service/local/staging/deploy/maven2") + Some("releases" at nexus + "service/local/staging/deploy/maven2") } -credentials += Credentials("Sonatype Nexus Repository Manager", +credentials += Credentials( + "Sonatype Nexus Repository Manager", "oss.sonatype.org", sys.props.getOrElse("SONATYPE_USERNAME", default = "biercoff"), - sys.props.getOrElse("SONATYPE_PASSWORD", default = "not_found")) + sys.props.getOrElse("SONATYPE_PASSWORD", default = "not_found") +) -publishArtifact in Test := false +Test / publishArtifact := false -pomIncludeRepository := { _ => false} +pomIncludeRepository := { _ => false } -unmanagedResourceDirectories in Compile += { +Compile / unmanagedResourceDirectories += { baseDirectory.value / "src/main/resources" } -fork in Test := true +Test / fork := true + pomExtra := @@ -68,21 +71,18 @@ resolvers += Classpaths.sbtPluginReleases resolvers += Resolver.typesafeRepo("releases") libraryDependencies ++= Seq( - "com.typesafe.play" %% "play-json" % "2.10.0-RC2", - "org.scalatestplus" %% "testng-6-7" % "3.2.5.0" % "test", - "com.github.nscala-time" %% "nscala-time" % "2.26.0", - "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2", - "org.reflections" % "reflections" % "0.9.12", - "ch.qos.logback" % "logback-classic" % "1.2.3", - "org.assertj" % "assertj-core" % "3.19.0", - "com.spatial4j" % "spatial4j" % "0.5", - "org.iban4j" % "iban4j" % "3.2.2-RELEASE", - "commons-validator" % "commons-validator" % "1.7", - "com.google.inject" % "guice" % "5.0.1", - "com.github.tototoshi" %% "scala-csv" % "1.3.7", - "com.google.zxing" % "core" % "3.4.1", - "io.github.classgraph" % "classgraph" % "4.8.102" + "com.typesafe.play" %% "play-json" % "2.10.0-RC9", + "org.scalatestplus" %% "testng-7-5" % "3.2.16.0" % "test", + "com.github.nscala-time" %% "nscala-time" % "2.32.0", + "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4", + "org.reflections" % "reflections" % "0.9.12", + "ch.qos.logback" % "logback-classic" % "1.2.3", + "org.assertj" % "assertj-core" % "3.19.0", + "com.spatial4j" % "spatial4j" % "0.5", + "org.iban4j" % "iban4j" % "3.2.2-RELEASE", + "commons-validator" % "commons-validator" % "1.7", + "com.google.inject" % "guice" % "5.0.1", + "com.github.tototoshi" %% "scala-csv" % "1.3.10", + "com.google.zxing" % "core" % "3.4.1", + "io.github.classgraph" % "classgraph" % "4.8.102" ) - - - diff --git a/project/build.properties b/project/build.properties index 0b2e09c..875b706 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.7 +sbt.version=1.9.2 diff --git a/project/plugins.sbt b/project/plugins.sbt index 7c1d9c7..4a6db9c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,15 +4,18 @@ resolvers += Classpaths.sbtPluginReleases resolvers += Classpaths.typesafeReleases -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.2.7") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") // Add the following to have Git manage your build versions resolvers += "jgit-repo" at "https://download.eclipse.org/jgit/maven" -resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns) -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") +resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))( + Resolver.ivyStylePatterns +) + +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") diff --git a/src/main/scala/fabricator/Alphanumeric.scala b/src/main/scala/fabricator/Alphanumeric.scala index c7243a1..0a1b9e0 100644 --- a/src/main/scala/fabricator/Alphanumeric.scala +++ b/src/main/scala/fabricator/Alphanumeric.scala @@ -24,6 +24,7 @@ case class Alphanumeric(private val random: Random = new Random()) { (min to max by step toList).asJava } + def randomIntsRange(min: Int, max: Int, step: Int): List[Int] = { if (step <= 0) throw new IllegalArgumentException("Step should be more then 0") min to max by step toList @@ -35,7 +36,6 @@ case class Alphanumeric(private val random: Random = new Random()) { def randomLong(min: Long, max: Long): Long = min + (Math.random() * (max - min)).toLong - def randomLongsRange(min: Long, max: Long, step: Long): List[Long] = { if (step <= 0) throw new IllegalArgumentException("Step should be more then 0") min to max by step toList @@ -53,7 +53,7 @@ case class Alphanumeric(private val random: Random = new Random()) { def randomDoublesRangeAsJavaList(min: Double, max: Double, step: Double): java.util.List[Double] = { if (step <= 0) throw new IllegalArgumentException("Step should be more then 0") - ((BigDecimal(min) to BigDecimal(max) by step).map(_.toDouble).toList).asJava + (BigDecimal(min) to BigDecimal(max) by step).map(_.toDouble).toList.asJava } def randomDoublesRange(min: Double, max: Double, step: Double): List[Double] = { @@ -69,12 +69,12 @@ case class Alphanumeric(private val random: Random = new Random()) { def randomFloatsRangeAsJavaList(min: Float, max: Float, step: Float): java.util.List[Float] = { if (step <= 0) throw new IllegalArgumentException("Step should be more then 0") - ((BigDecimal(min) to BigDecimal(max) by step).map(_.toFloat).toList).asJava + (BigDecimal(min) to BigDecimal(max) by BigDecimal(step)).map(_.toFloat).toList.asJava } def randomFloatsRange(min: Float, max: Float, step: Float): List[Float] = { if (step <= 0) throw new IllegalArgumentException("Step should be more then 0") - (BigDecimal(min) to BigDecimal(max) by step).map(_.toFloat).toList + (BigDecimal(min) to BigDecimal(max) by BigDecimal(step)).map(_.toFloat).toList } def randomBoolean: Boolean = random.nextBoolean() @@ -88,23 +88,26 @@ case class Alphanumeric(private val random: Random = new Random()) { def randomStringsAsJavaList: util.List[String] = randomStrings(5, 100, 100).asJava def randomStrings(minLength: Int, maxLength: Int, amount: Int): List[String] = { - if (minLength != maxLength )List.fill(amount)(randomString(randomInt(minLength, maxLength))) else + if (minLength != maxLength) List.fill(amount)(randomString(randomInt(minLength, maxLength))) + else List.fill(amount)(randomString(minLength)) } def randomStringsAsJavaList(minLength: Int, maxLength: Int, amount: Int): java.util.List[String] = { - if (minLength != maxLength )List.fill(amount)(randomString(randomInt(minLength, maxLength))).asJava else + if (minLength != maxLength) List.fill(amount)(randomString(randomInt(minLength, maxLength))).asJava + else List.fill(amount)(randomString(minLength)).asJava } - def randomString(length: Int): String = randomString("0123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_", length) + def randomString(length: Int): String = + randomString("0123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_", length) def randomString(charSeq: String, max: Int): String = string(charSeq, max) private def string(charsSequence: String, max: Int): String = { val builder = new StringBuilder - (0 until max).foreach { - _ => builder.append(charsSequence.charAt(random.nextInt(charsSequence.length - 1))) + (0 until max).foreach { _ => + builder.append(charsSequence.charAt(random.nextInt(charsSequence.length - 1))) } builder.toString() } @@ -113,24 +116,26 @@ case class Alphanumeric(private val random: Random = new Random()) { def randomHash(length: Int): String = string("0123456789abcdef", length) - def randomHashList: List[String] = randomHashList(40,40, 100) + def randomHashList: List[String] = randomHashList(40, 40, 100) def randomHashList(minLength: Int, maxLength: Int, amount: Int): List[String] = { - if (minLength != maxLength )List.fill(amount)(randomHash(randomInt(minLength, maxLength))) else + if (minLength != maxLength) List.fill(amount)(randomHash(randomInt(minLength, maxLength))) + else List.fill(amount)(randomHash(minLength)) } - def randomHashAsJavaList: util.List[String] = randomHashList(40,40, 100).asJava + def randomHashAsJavaList: util.List[String] = randomHashList(40, 40, 100).asJava def randomHashAsJavaList(minLength: Int, maxLength: Int, amount: Int): util.List[String] = { - if (minLength != maxLength )List.fill(amount)(randomHash(randomInt(minLength, maxLength))).asJava else + if (minLength != maxLength) List.fill(amount)(randomHash(randomInt(minLength, maxLength))).asJava + else List.fill(amount)(randomHash(minLength)).asJava } def randomGuid: String = randomGuid(5) def randomGuid(version: Int): String = { - val guidPool = "abcdef1234567890" + val guidPool = "abcdef1234567890" val variantPool = "ab89" string(guidPool, 8) + "-" + string(guidPool, 4) + "-" + @@ -158,7 +163,10 @@ case class Alphanumeric(private val random: Random = new Random()) { def botifyAsJavaList(pattern: String, amount: Int): util.List[String] = botifyList(pattern, amount).asJava def numerify(pattern: String): String = { - pattern.map { case '#' => random.nextInt(10).toString case letter => letter}.mkString + pattern.map { + case '#' => random.nextInt(10).toString + case letter => letter + }.mkString } def numerifyList(pattern: String, amount: Int): List[String] = List.fill(amount)(numerify(pattern)) @@ -167,7 +175,10 @@ case class Alphanumeric(private val random: Random = new Random()) { def letterify(pattern: String): String = { val chars = ('a' to 'z') ++ ('A' to 'Z') - pattern.map { case '?' => chars(random.nextInt(chars.length)) case letter => letter}.mkString + pattern.map { + case '?' => chars(random.nextInt(chars.length)) + case letter => letter + }.mkString } def letterifyList(pattern: String, amount: Int): List[String] = List.fill(amount)(letterify(pattern)) diff --git a/src/main/scala/fabricator/Contact.scala b/src/main/scala/fabricator/Contact.scala index 0912164..a76cd32 100644 --- a/src/main/scala/fabricator/Contact.scala +++ b/src/main/scala/fabricator/Contact.scala @@ -1,11 +1,13 @@ package fabricator -import com.github.nscala_time.time.Imports._ -import fabricator.enums.DateFormat import org.joda.time.format.DateTimeFormatter +import com.github.nscala_time.time.Imports._ + import scala.util.Random +import fabricator.enums.DateFormat + object Contact { def apply(): Contact = { @@ -18,22 +20,25 @@ object Contact { } -class Contact(private val utility: UtilityService, - private val alpha: Alphanumeric, - private val random: Random) { +class Contact(private val utility: UtilityService, private val alpha: Alphanumeric, private val random: Random) { def fullName(setPrefix: Boolean, setSuffix: Boolean): String = { (setPrefix, setSuffix) match { - case (`setPrefix` , `setSuffix`) if setPrefix && !setSuffix => String.format("%s %s %s", prefix, firstName, lastName) - case (`setPrefix` , `setSuffix`) if setPrefix && setSuffix => String.format("%s %s %s %s", prefix, firstName, lastName, suffix) - case (`setPrefix` , `setSuffix`) if setPrefix && setSuffix => String.format("%s %s %s", firstName, lastName, suffix) + case (`setPrefix`, `setSuffix`) if setPrefix && !setSuffix => + String.format("%s %s %s", prefix, firstName, lastName) + case (`setPrefix`, `setSuffix`) if setPrefix && setSuffix => + String.format("%s %s %s %s", prefix, firstName, lastName, suffix) + case (`setPrefix`, `setSuffix`) if setPrefix && setSuffix => + String.format("%s %s %s", firstName, lastName, suffix) case _ => firstName + " " + lastName } } - def birthday(age: Int): String = DateTimeFormat.forPattern(DateFormat.dd_MM_yyyy.getFormat).print(DateTime.now - age.years) + def birthday(age: Int): String = + DateTimeFormat.forPattern(DateFormat.dd_MM_yyyy.getFormat).print(DateTime.now() - age.years) - def birthday(age: Int, format: DateFormat): String = DateTimeFormat.forPattern(format.getFormat).print(DateTime.now - age.years) + def birthday(age: Int, format: DateFormat): String = + DateTimeFormat.forPattern(format.getFormat).print(DateTime.now() - age.years) def eMail: String = { (firstName.toLowerCase + "_" + lastName.toLowerCase + alpha.numerify("###")).replaceAll(" ", "") + "@" + utility @@ -42,11 +47,11 @@ class Contact(private val utility: UtilityService, } def prefix: String = utility.getValueFromArray("prefix") - + def suffix: String = utility.getValueFromArray("suffix") - + def firstName: String = utility.getValueFromArray("first_name") - + def lastName: String = utility.getValueFromArray("last_name") def phoneNumber: String = alpha.numerify(utility.getValueFromArray("phone_formats")) @@ -60,9 +65,9 @@ class Contact(private val utility: UtilityService, def apartmentNumber: String = alpha.numerify(utility.getValueFromArray("app_number")) def postcode: String = alpha.botify(utility.getValueFromArray("postcode")).toUpperCase - + def country: String = utility.getValueFromArray("country") - + def city: String = utility.getValueFromArray("city_prefix") + utility.getValueFromArray("city_suffix") def state: String = utility.getValueFromArray("state") @@ -77,7 +82,7 @@ class Contact(private val utility: UtilityService, */ def bsn: String = { val firstFour: String = alpha.randomInt(1000, 9999).toString - val secondFour = firstFour.reverse + val secondFour = firstFour.reverse firstFour + secondFour + "0" } @@ -88,12 +93,12 @@ class Contact(private val utility: UtilityService, def zodiac(birthday: String): String = { try { val formatter: DateTimeFormatter = DateTimeFormat.forPattern("dd-MM-yyyy") - val date = formatter.parseDateTime(birthday) + val date = formatter.parseDateTime(birthday) date.getDayOfYear match { - case it if 1 until 20 contains it => "Capricorn" - case it if 20 until 50 contains it => "Aquarius" - case it if 50 until 80 contains it => "Pisces" - case it if 80 until 110 contains it => "Aries" + case it if 1 until 20 contains it => "Capricorn" + case it if 20 until 50 contains it => "Aquarius" + case it if 50 until 80 contains it => "Pisces" + case it if 80 until 110 contains it => "Aries" case it if 110 until 141 contains it => "Taurus" case it if 141 until 172 contains it => "Gemini" case it if 172 until 204 contains it => "Cancer" @@ -102,7 +107,7 @@ class Contact(private val utility: UtilityService, case it if 266 until 296 contains it => "Libra" case it if 296 until 326 contains it => "Scorpio" case it if 326 until 356 contains it => "Sagittarius" - case it if 356 to 365 contains it => "Capricorn" + case it if 356 to 365 contains it => "Capricorn" } } catch { case _: IllegalArgumentException => throw new IllegalArgumentException("Format of the date should be dd-MM-yyyy") @@ -110,10 +115,12 @@ class Contact(private val utility: UtilityService, } def height(cm: Boolean): String = { - if (cm) alpha.randomDouble(1.50, 2.20).toString.substring(0,4) + " cm" else alpha.randomInt(150, 220).toString + " m" + if (cm) alpha.randomDouble(1.50, 2.20).toString.substring(0, 4) + " cm" + else alpha.randomInt(150, 220).toString + " m" } - def weight(metric: Boolean): String = if (metric) alpha.randomInt(50, 110).toString + " kg" else alpha.randomInt(30, 90).toString + " lbs" + def weight(metric: Boolean): String = + if (metric) alpha.randomInt(50, 110).toString + " kg" else alpha.randomInt(30, 90).toString + " lbs" def bloodType: String = utility.getValueFromArray("blood_type") diff --git a/src/main/scala/fabricator/Mobile.scala b/src/main/scala/fabricator/Mobile.scala index 9d06157..1020935 100644 --- a/src/main/scala/fabricator/Mobile.scala +++ b/src/main/scala/fabricator/Mobile.scala @@ -2,8 +2,7 @@ package fabricator import scala.util.Random -case class Mobile(private val random: Random = new Random(), - private val alpha: Alphanumeric = Alphanumeric()) { +case class Mobile(private val random: Random = new Random(), private val alpha: Alphanumeric = Alphanumeric()) { /** * Android GCM Registration ID @@ -13,9 +12,10 @@ case class Mobile(private val random: Random = new Random(), def applePushToken: String = alpha.randomString("abcdef1234567890", 64) - def wp8_anid2: String = new sun.misc.BASE64Encoder().encode(alpha.randomString.getBytes("UTF-8")) + def wp8_anid2: String = new String(java.util.Base64.getEncoder().encode(alpha.randomString.getBytes("UTF-8"))) - def wp7_anid: String = "A=" + alpha.randomGuid.replace("-", "").toUpperCase + "&E=" + alpha.randomHash(3) + "&W=" + alpha.randomInt(0, 9) + def wp7_anid: String = + "A=" + alpha.randomGuid.replace("-", "").toUpperCase + "&E=" + alpha.randomHash(3) + "&W=" + alpha.randomInt(0, 9) def blackBerryPin: String = alpha.randomHash(8) diff --git a/src/main/scala/fabricator/entities/RelativeDate.scala b/src/main/scala/fabricator/entities/RelativeDate.scala index 3e86b15..e8d6338 100644 --- a/src/main/scala/fabricator/entities/RelativeDate.scala +++ b/src/main/scala/fabricator/entities/RelativeDate.scala @@ -1,18 +1,18 @@ package fabricator.entities -import fabricator.enums.DateFormat import org.joda.time.{DateTime, DateTimeZone} +import fabricator.enums.DateFormat + class RelativeDate(private val initialDate: DateTime = DateTime.now()) { - def this(timeZone: DateTimeZone) { + def this(timeZone: DateTimeZone) = { this(DateTime.now(timeZone)) } private var date = initialDate - - def tomorrow() : this.type = { + def tomorrow(): this.type = { date = date.plusDays(1) this } @@ -26,7 +26,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { years match { case `years` if years > 0 => date = date.plusYears(years) case `years` if years < 0 => date = date.minusYears(Math.abs(years)) - case _ => // skip + case _ => // skip } this } @@ -35,7 +35,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { months match { case `months` if months > 0 => date = date.plusMonths(months) case `months` if months < 0 => date = date.minusMonths(Math.abs(months)) - case _ => // skip + case _ => // skip } this } @@ -44,7 +44,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { weeks match { case `weeks` if weeks > 0 => date = date.plusWeeks(weeks) case `weeks` if weeks < 0 => date = date.minusWeeks(Math.abs(weeks)) - case _ => // skip + case _ => // skip } this } @@ -53,7 +53,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { days match { case `days` if days > 0 => date = date.plusDays(days) case `days` if days < 0 => date = date.minusDays(Math.abs(days)) - case _ => // skip + case _ => // skip } this } @@ -62,7 +62,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { hours match { case `hours` if hours > 0 => date = date.plusHours(hours) case `hours` if hours < 0 => date = date.minusHours(Math.abs(hours)) - case _ => // skip + case _ => // skip } this } @@ -71,7 +71,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { minutes match { case `minutes` if minutes > 0 => date = date.plusMinutes(minutes) case `minutes` if minutes < 0 => date = date.minusMinutes(Math.abs(minutes)) - case _ => // skip + case _ => // skip } this } @@ -80,7 +80,7 @@ class RelativeDate(private val initialDate: DateTime = DateTime.now()) { seconds match { case `seconds` if seconds > 0 => date = date.plusSeconds(seconds) case `seconds` if seconds < 0 => date = date.minusSeconds(Math.abs(seconds)) - case _ => // skip + case _ => // skip } this } diff --git a/src/main/scala/fabricator/entities/UrlBuilder.scala b/src/main/scala/fabricator/entities/UrlBuilder.scala index b4a2794..24d7a57 100644 --- a/src/main/scala/fabricator/entities/UrlBuilder.scala +++ b/src/main/scala/fabricator/entities/UrlBuilder.scala @@ -1,15 +1,16 @@ package fabricator.entities import java.net.URL -import java.nio.charset.Charset import java.nio.{ByteBuffer, CharBuffer} +import java.nio.charset.Charset import com.sun.jndi.toolkit.url.Uri -import fabricator._ -import scala.util.Random -import scala.collection.JavaConverters._ import scala.collection.mutable +import scala.collection.JavaConverters._ +import scala.util.Random + +import fabricator._ class UrlBuilder() { @@ -101,7 +102,7 @@ class UrlBuilder() { if (!useCustomHost) builder.append(domain) if (port != 80) builder.append(":" + port.toString) builder.append(path) - val paramsString = convertParamsToString(params) + val paramsString = convertParamsToString(params) val encodedParams = urlEncode(paramsString, encoding) builder.append(if (encodeParams) encodedParams else paramsString) builder.toString() @@ -110,31 +111,31 @@ class UrlBuilder() { private def urlEncode(input: String, charset: Charset): String = { val builder: StringBuilder = new StringBuilder() val charBuffer: CharBuffer = CharBuffer.allocate(1) - for (char <- input.toCharArray) { + for (char <- input.toCharArray) char match { - case ' ' => builder.append('+') + case ' ' => builder.append('+') case `char` if isUrlSafe(char) => builder.append(char) - case _ => appendEncodedChar(char, builder, charBuffer, charset) + case _ => appendEncodedChar(char, builder, charBuffer, charset) } - } builder.toString() } - private def appendEncodedChar(char: Char, stringBuilder: StringBuilder, charBuffer: CharBuffer, charset: Charset) { - charBuffer.put(0, char) - charBuffer.rewind() - val byteBuffer: ByteBuffer = charset.encode(charBuffer) - for (i <- 0 until byteBuffer.limit() by 1) { - stringBuilder.append('%') - val placeHolder = "%1$02X" - stringBuilder.append(placeHolder.format(byteBuffer.get(i))) + + private def appendEncodedChar(char: Char, stringBuilder: StringBuilder, charBuffer: CharBuffer, charset: Charset) = { + charBuffer.put(0, char) + charBuffer.rewind() + val byteBuffer: ByteBuffer = charset.encode(charBuffer) + for (i <- 0 until byteBuffer.limit() by 1) { + stringBuilder.append('%') + val placeHolder = "%1$02X" + stringBuilder.append(placeHolder.format(byteBuffer.get(i))) } } private def isUrlSafe(c: Char): Boolean = { ('a' <= c && 'z' >= c) || - ('A' <= c && 'Z' >= c) || - ('0' <= c && '9' >= c) || - (c == '-' || c == '_' || c == '.' || c == '~' || c == ' ') + ('A' <= c && 'Z' >= c) || + ('0' <= c && '9' >= c) || + (c == '-' || c == '_' || c == '.' || c == '~' || c == ' ') } private def convertParamsToString(params: mutable.Map[String, Any]): String = { @@ -144,22 +145,22 @@ class UrlBuilder() { validateParam(value) builder.append(key + "=" + value + "&") } - builder.toString().replaceAll(" ", "+")substring(0, builder.length-1) + builder.toString().replaceAll(" ", "+") substring (0, builder.length - 1) } private def validateParam(param: Any) = { param match { - case z: Boolean => // accept it - case c: Char => // accept it - case s: Short => // accept it - case i: Int => // accept it - case j: Long => // accept it - case f: Float => // accept it - case d: Double => // accept it + case z: Boolean => // accept it + case c: Char => // accept it + case s: Short => // accept it + case i: Int => // accept it + case j: Long => // accept it + case f: Float => // accept it + case d: Double => // accept it case str: String => // accept it - case _ => throw new IllegalArgumentException("Only String ,Int, Double, Float, Boolean are acceptable for url params") + case _ => + throw new IllegalArgumentException("Only String ,Int, Double, Float, Boolean are acceptable for url params") } } - } diff --git a/src/test/scala/fabricator/AlphaNumericTestSuite.scala b/src/test/scala/fabricator/AlphaNumericTestSuite.scala index afe357d..2a68030 100644 --- a/src/test/scala/fabricator/AlphaNumericTestSuite.scala +++ b/src/test/scala/fabricator/AlphaNumericTestSuite.scala @@ -6,7 +6,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "numerifyDP") def numerifyDP = { - Array(Array("###ABC", "\\d{3}\\w{3}"), + Array( + Array("###ABC", "\\d{3}\\w{3}"), Array("###ABC###", "\\d{3}\\w{3}\\d{3}"), Array("ABC###", "\\w{3}\\d{3}"), Array("A#B#C#", "\\w{1}\\d{1}\\w{1}\\d{1}\\w{1}\\d{1}"), @@ -31,7 +32,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "letterifyDP") def letterifyDP = { - Array(Array("???123", "\\w{3}\\d{3}"), + Array( + Array("???123", "\\w{3}\\d{3}"), Array("???123???", "\\w{3}\\d{3}\\w{3}"), Array("123???", "\\d{3}\\w{3}"), Array("1?2?3?", "\\d{1}\\w{1}\\d{1}\\w{1}\\d{1}\\w{1}"), @@ -56,7 +58,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "botifyDP") def botifyDP = { - Array(Array("???123###", "\\w{3}\\d{6}"), + Array( + Array("???123###", "\\w{3}\\d{6}"), Array("???123???###", "\\w{3}\\d{3}\\w{3}\\d{3}"), Array("123???", "\\d{3}\\w{3}"), Array("1?2?3?", "\\d{1}\\w{1}\\d{1}\\w{1}\\d{1}\\w{1}"), @@ -79,32 +82,34 @@ class AlphaNumericTestSuite extends BaseTestSuite { list.foreach(x => assert(x.matches("\\w{3}\\d{6}"))) } - @Test - def testDefaultInteger() { + def testDefaultInteger() = { val integer = alpha.randomInt - if (debugEnabled) logger.debug("Checking default integer function. Should return random integer below 1000 : " + integer) + if (debugEnabled) + logger.debug("Checking default integer function. Should return random integer below 1000 : " + integer) assert(0 to 1000 contains integer) assert(integer.isInstanceOf[Int]) } @Test - def testDefaultLong() { + def testDefaultLong() = { val longNumber = alpha.randomLong - if (debugEnabled) logger.debug("Checking default longNumber function. Should return random longNumber below 1000 : " + longNumber) + if (debugEnabled) + logger.debug("Checking default longNumber function. Should return random longNumber below 1000 : " + longNumber) assert(longNumber.isInstanceOf[Long]) } @Test - def testDefaultDouble() { + def testDefaultDouble() = { val double = alpha.randomDouble - if (debugEnabled) logger.debug("Checking default double function. Should return random double below 1000 : " + double) + if (debugEnabled) + logger.debug("Checking default double function. Should return random double below 1000 : " + double) assert(double > 0 && double < 1000) assert(double.isInstanceOf[Double]) } @Test - def testDefaultFloat() { + def testDefaultFloat() = { val float = alpha.randomFloat if (debugEnabled) logger.debug("Checking default float function. Should return random float below 1000 : " + float) assert(float > 0 && float < 1000) @@ -112,16 +117,17 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test - def testDefaultGausian() { + def testDefaultGausian() = { val gausian = alpha.randomGausian - if (debugEnabled) logger.debug("Checking default gausian function. Should return random gausian below 1000 : " + gausian) + if (debugEnabled) + logger.debug("Checking default gausian function. Should return random gausian below 1000 : " + gausian) assert(gausian < 1000) assert(gausian.isInstanceOf[Double]) } @Test - def testDefaultBoolean() { - var trueCount = 0 + def testDefaultBoolean() = { + var trueCount = 0 var falseCount = 0 for (i <- 0 to 100) { val boolean = alpha.randomBoolean @@ -132,7 +138,7 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test - def testDefaultString() { + def testDefaultString() = { val string = alpha.randomString if (debugEnabled) logger.debug("Checking default string function. Should return random string below 30 : " + string) assert(string.length == 30) @@ -140,22 +146,25 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test - def testCustomString() { + def testCustomString() = { val extendedString = alpha.randomString(50) - if (debugEnabled) logger.debug("Checking default extendedString function. Should return random extendedString below 50 : " + extendedString) + if (debugEnabled) + logger.debug( + "Checking default extendedString function. Should return random extendedString below 50 : " + extendedString + ) assert(extendedString.length == 50) assert(extendedString.isInstanceOf[String]) } @Test - def testDefaultStringsList() { + def testDefaultStringsList() = { val strings = alpha.randomStrings assertResult(100)(strings.length) strings.foreach(string => assert(string.length >= 5 && string.length <= 100)) } @Test - def testCustomStringsList() { + def testCustomStringsList() = { val strings = alpha.randomStrings(10, 10, 20) assertResult(20)(strings.length) strings.foreach(string => assert(string.length >= 10 && string.length <= 10)) @@ -163,7 +172,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "charSets") def charSets() = { - Array(Array("aaaa", 10), + Array( + Array("aaaa", 10), Array("1234567890", 100), Array("0123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_", 500), Array("!@#$%^&*()_+{}\"|:?><", 30) @@ -173,54 +183,56 @@ class AlphaNumericTestSuite extends BaseTestSuite { @Test(dataProvider = "charSets") def testCustomStringWithSpecificCharSet(charSet: String, max: Int) = { val string = alpha.randomString(charSet, max) - if (debugEnabled) logger.debug("Checking default extendedString function. Should return random extendedString below " + max + " : " + string) + if (debugEnabled) + logger.debug( + "Checking default extendedString function. Should return random extendedString below " + max + " : " + string + ) assert(string.length == max) for (symbol <- string) assert(charSet.contains(symbol)) } - @DataProvider(name = "numbersCustomTypes") - def numbersCustomTypes() = { - Array(Array(100, classOf[Integer]), - Array(100.10, classOf[java.lang.Double]), - Array(100.10f, classOf[java.lang.Float]), - Array(100000000000L, classOf[java.lang.Long]) + def numbersCustomTypes(): Array[Array[Any]] = { + Array[Array[Any]]( + Array(100), + Array(100.10), + Array(100.10f), + Array(100000000000L) ) } @Test(dataProvider = "numbersCustomTypes") - def testCustomNumberType(maxValue: Any, numberType: Any) { + def testCustomNumberType(maxValue: Any, numberType: Any) = { def calculate(randomNumber: Any): Any = randomNumber match { - case number: Int => alpha.randomInt(number) + case number: Int => alpha.randomInt(number) case number: Double => alpha.randomDouble(number) - case number: Float => alpha.randomFloat(number) - case number: Long => alpha.randomLong(number) + case number: Float => alpha.randomFloat(number) + case number: Long => alpha.randomLong(number) } val result = calculate(maxValue) - if (debugEnabled) logger.debug("Checking custom number with " + numberType + " type function. Should return with specific type and below specified value : ") + if (debugEnabled) + logger.debug( + "Checking custom number with " + numberType + " type function. Should return with specific type and below specified value : " + ) assertResult(result.getClass)(numberType) assert(util.isLess(result, maxValue)) } @DataProvider(name = "numbersRandomRange") def numbersRandomRange(): Array[Array[Any]] = { - Array(Array(100, 150), - Array(100.10, 200.01), - Array(100.10f, 250.10f), - Array(1L, 100L) - ) + Array[Array[Any]](Array(100, 150), Array(100.10d, 200.01d), Array(100.10f, 250.10f), Array(1L, 100L)) } @Test(dataProvider = "numbersRandomRange") - def testNumbersRandomRange(min: Any, max: Any) { + def testNumbersRandomRange(min: Any, max: Any) = { def calculate(minValue: Any, maxValue: Any): Any = (minValue, maxValue) match { - case (min: Int, max: Int) => alpha.randomInt(min, max) + case (min: Int, max: Int) => alpha.randomInt(min, max) case (min: Double, max: Double) => alpha.randomDouble(min, max) - case (min: Float, max: Float) => alpha.randomFloat(min, max) - case (min: Long, max: Long) => alpha.randomLong(min, max) - case(_, _) => + case (min: Float, max: Float) => alpha.randomFloat(min, max) + case (min: Long, max: Long) => alpha.randomLong(min, max) + case (_, _) => } val actualNumber = calculate(min, max) if (debugEnabled) logger.debug("Checking random number in range: " + actualNumber) @@ -231,7 +243,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "integerRangeWithStep") def integerRangeWithStep(): Array[Array[Any]] = { - Array(Array(1, 10, 1, List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), + Array[Array[Any]]( + Array(1, 10, 1, List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), Array(1, 10, 2, List(1, 3, 5, 7, 9)), Array(1, 10, 0, List(1, 3, 5, 7, 9)), Array(1, 10, -1, List(1, 3, 5, 7, 9)) @@ -239,11 +252,11 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test(dataProvider = "integerRangeWithStep") - def testIntegerRangeWithStep(min: Int, max: Int, step: Int, expectedResult: List[Int]) { + def testIntegerRangeWithStep(min: Int, max: Int, step: Int, expectedResult: List[Int]) = { if (step <= 0) { - try { + try alpha.randomIntsRange(min, max, step) - } catch { + catch { case e: IllegalArgumentException => assertResult(e.getMessage)("Step should be more then 0") } } else { @@ -255,7 +268,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "doubleRangeWithStep") def doubleRangeWithStep(): Array[Array[Any]] = { - Array(Array(1, 10, 1, List(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)), + Array[Array[Any]]( + Array(1, 10, 1, List(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)), Array(1, 10, 2, List(1.0, 3.0, 5.0, 7.0, 9.0)), Array(1, 3, 0.5, List(1.0, 1.5, 2.0, 2.5, 3.0)), Array(1, 3, -1, List(1.0, 1.5, 2.0, 2.5, -1.0)), @@ -264,11 +278,11 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test(dataProvider = "doubleRangeWithStep") - def testDoubleRangeWithStep(min: Double, max: Double, step: Double, expectedResult: List[Double]) { + def testDoubleRangeWithStep(min: Double, max: Double, step: Double, expectedResult: List[Double]) = { if (step <= 0) { - try { + try alpha.randomDoublesRange(min, max, step) - } catch { + catch { case e: IllegalArgumentException => assertResult(e.getMessage)("Step should be more then 0") } } else { @@ -279,7 +293,8 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "floatRangeWithStep") def floatRangeWithStep(): Array[Array[Any]] = { - Array(Array(1.0f, 10.0f, 1.0f, List(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)), + Array[Array[Any]]( + Array(1.0f, 10.0f, 1.0f, List(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)), Array(1.0f, 10.0f, 2.0f, List(1.0f, 3.0f, 5.0f, 7.0f, 9.0f)), Array(1.0f, 3.0f, 0.5f, List(1.0f, 1.5f, 2.0f, 2.5f, 3.0f)), Array(1.0f, 3.0f, 0.0f, List(1.0f, 1.5f, 2.0f, 2.5f, 3.0f)), @@ -288,11 +303,11 @@ class AlphaNumericTestSuite extends BaseTestSuite { } @Test(dataProvider = "floatRangeWithStep") - def testFloatRangeWithStep(min: Float, max: Float, step: Float, expectedResult: List[Float]) { + def testFloatRangeWithStep(min: Float, max: Float, step: Float, expectedResult: List[Float]) = { if (step <= 0) { - try { + try alpha.randomFloatsRange(min, max, step) - } catch { + catch { case e: IllegalArgumentException => assertResult(e.getMessage)("Step should be more then 0") } } else { @@ -303,17 +318,18 @@ class AlphaNumericTestSuite extends BaseTestSuite { @DataProvider(name = "longRangeWithStep") def longRangeWithStep(): Array[Array[Any]] = { - Array(Array(1L, 10L, 1L, List(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), + Array[Array[Any]]( + Array(1L, 10L, 1L, List(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), Array(1L, 10L, 2L, List(1L, 3L, 5L, 7L, 9L)) ) } @Test(dataProvider = "longRangeWithStep") - def testLongRangeWithStep(min: Long, max: Long, step: Long, expectedResult: List[Long]) { + def testLongRangeWithStep(min: Long, max: Long, step: Long, expectedResult: List[Long]) = { if (step <= 0) { - try { + try alpha.randomLongsRange(min, max, step) - } catch { + catch { case e: IllegalArgumentException => assertResult(e.getMessage)("Step should be more then 0") } } else { @@ -357,5 +373,4 @@ class AlphaNumericTestSuite extends BaseTestSuite { assertResult(30)(customList.size) } - } diff --git a/src/test/scala/fabricator/CalendarTestSuite.scala b/src/test/scala/fabricator/CalendarTestSuite.scala index 4fb2bc4..3ff93db 100644 --- a/src/test/scala/fabricator/CalendarTestSuite.scala +++ b/src/test/scala/fabricator/CalendarTestSuite.scala @@ -1,24 +1,23 @@ package fabricator -import fabricator.enums.DateFormat._ -import fabricator.enums.DateRangeType._ -import fabricator.enums.{DateFormat, DateRangeType} import org.joda.time.{DateTime, DateTimeZone} import org.testng.annotations.{DataProvider, Test} +import fabricator.enums.{DateFormat, DateRangeType} +import fabricator.enums.DateFormat._ +import fabricator.enums.DateRangeType._ + class CalendarTestSuite extends BaseTestSuite { lazy val daysOfWeekList = util.getArrayFromJson("day_of_week") @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customCalender = fabricator.Calendar(lang) assert(customCalender != null) } @@ -32,7 +31,8 @@ class CalendarTestSuite extends BaseTestSuite { @DataProvider(name = "dateFormats") def dateFormats() = { - Array(Array(dd_mm_yyyy_SEMICOLON, "\\d{2}:\\d{2}:\\d{4}"), + Array( + Array(dd_mm_yyyy_SEMICOLON, "\\d{2}:\\d{2}:\\d{4}"), Array(mm_dd_yyyy_SEMICOLON, "\\d{2}:\\d{2}:\\d{4}"), Array(dd_MM_yyyy_SEMICOLON, "\\d{2}:\\d{2}:\\d{4}"), Array(dd_MM_YYYY_SEMICOLON, "\\d{2}:\\d{2}:\\d{4}"), @@ -72,11 +72,11 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testDateGetterAsDate() = { - val year = calendar.year.toInt - val month = calendar.month.toInt - val day = calendar.day(year, month).toInt - val hour = calendar.hour12h.toInt - val minute = calendar.minute.toInt + val year = calendar.year.toInt + val month = calendar.month.toInt + val day = calendar.day(year, month).toInt + val hour = calendar.hour12h.toInt + val minute = calendar.minute.toInt val expectedDate = new DateTime(year, month, day, hour, minute) val date = calendar.randomDate .inYear(year) @@ -88,12 +88,11 @@ class CalendarTestSuite extends BaseTestSuite { assertResult(expectedDate)(date) } - @Test def testAmPm() = { var amCount = 0 var pmCount = 0 - for (i <- 1 to 50){ + for (i <- 1 to 50) { val ampm = calendar.ampm if (ampm.equals("am")) amCount = amCount + 1 else pmCount = pmCount + 1 if (debugEnabled) logger.debug("Testing random amPm value : " + ampm) @@ -125,12 +124,12 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testTime() = { - val time24 = calendar.time24h - val hour24 = time24.split(":")(0).toInt + val time24 = calendar.time24h + val hour24 = time24.split(":")(0).toInt val minute24 = time24.split(":")(1).toInt assert(hour24 >= 0 && hour24 < 24 && minute24 >= 0 && minute24 < 60) - val time = calendar.time12h - val hour = time.split(":")(0).toInt + val time = calendar.time12h + val hour = time.split(":")(0).toInt val minute = time.split(":")(1).toInt assert(hour >= 0 && hour < 12 && minute >= 0 && minute < 60) } @@ -143,9 +142,9 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testDay() = { - val year = calendar.year + val year = calendar.year val month = calendar.month - val day = calendar.day(year.toInt, month.toInt) + val day = calendar.day(year.toInt, month.toInt) if (debugEnabled) logger.debug("Testing random day value: " + day) assert(day.toInt >= 0 && day.toInt < 31) } @@ -155,29 +154,26 @@ class CalendarTestSuite extends BaseTestSuite { val dayOfWeek = calendar.dayOfWeek assert(daysOfWeekList.contains(dayOfWeek)) } - + @DataProvider(name = "dayExceptionDP") - def dayExceptionDP():Array[Array[Any]] = { - Array(Array(0, 12), - Array(1, 32), - Array(32, 10) - ) + def dayExceptionDP(): Array[Array[Int]] = { + Array(Array(0, 12), Array(1, 32), Array(32, 10)) } - + @Test(dataProvider = "dayExceptionDP") def testDayException(min: Int, max: Int) = { try { val date = calendar.day(2000, 2, min, max) - } catch { + } catch { case e: IllegalArgumentException => assertResult("min and max values should be in [1,31] range")(e.getMessage) } } @Test def testCustomDay() = { - val year = calendar.year.toInt + val year = calendar.year.toInt val month = calendar.month.toInt - val day = calendar.day(year, month, 10, 20 ).toInt + val day = calendar.day(year, month, 10, 20).toInt if (debugEnabled) logger.debug("Testing random custom day value in range [10,20]: " + day) assert(day >= 10 && day <= 20) } @@ -188,7 +184,7 @@ class CalendarTestSuite extends BaseTestSuite { if (debugEnabled) logger.debug("Checking random month value numeric: " + monthNumber) assert(monthNumber.toInt > 0 && monthNumber.toInt < 12) val monthLettered = calendar.month(asNumber = false) - val months = util.getArrayFromJson("month") + val months = util.getArrayFromJson("month") assert(months.contains(monthLettered)) } @@ -202,27 +198,29 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testCentury() = { val centuryList = util.getArrayFromJson("centuries") - val century = calendar.century + val century = calendar.century assert(centuryList.contains(century)) } @DataProvider - def dateDP():Array[Array[Any]] = { - Array(Array(2014, 2, 30, 0, 0, "28-02-2014 00:00"), + def dateDP(): Array[Array[Any]] = { + Array[Array[Any]]( + Array(2014, 2, 30, 0, 0, "28-02-2014 00:00"), Array(1000, 2, 30, 0, 0, "28-02-1000 00:00"), Array(1980, 1, 50, 12, 30, "31-01-1980 12:30"), - Array(2250, 2, 30, 0, 0, "28-02-2250 00:00")) + Array(2250, 2, 30, 0, 0, "28-02-2250 00:00") + ) } @Test(dataProvider = "dateDP") def testDate(year: Int, month: Int, day: Int, hour: Int, minute: Int, expectedResult: String) = { val date = calendar.randomDate - .inYear(year) - .inMonth(month) - .inDay(day) - .inHour(hour) - .inMinute(minute) - .asString(dd_MM_yyyy_HH_mm) + .inYear(year) + .inMonth(month) + .inDay(day) + .inHour(hour) + .inMinute(minute) + .asString(dd_MM_yyyy_HH_mm) if (debugEnabled) logger.debug("Testing random date: " + date) assert(date.equals(expectedResult)) } @@ -234,46 +232,54 @@ class CalendarTestSuite extends BaseTestSuite { assert(date.getMinuteOfHour == 10) } - @DataProvider - def datesRangeDP():Array[Array[Any]] = { - Array(Array(2001, 1, 1, 2010, 1, 1,YEARS, 1, 9), - Array(2001, 1, 1, 2010, 1, 1,YEARS, 2, 5), - Array(2001, 1, 1, 2010, 1, 1,MONTHS, 1, 108), - Array(2001, 1, 1, 2010, 1, 1,MONTHS, 2, 54), - Array(2001, 1, 1, 2010, 1, 1,WEEKS, 2, 235), - Array(2001, 1, 1, 2001, 10, 1,DAYS, 10, 28), - Array(2001, 1, 1, 2001, 10, 1,HOURS, 10, 656), - Array(2001, 1, 1, 2001, 10, 1,MINUTES, 10, 39306), - Array(2001, 1, 1, 2001, 1, 3,SECONDS, 1000, 173) + def datesRangeDP(): Array[Array[Any]] = { + Array[Array[Any]]( + Array(2001, 1, 1, 2010, 1, 1, YEARS, 1, 9), + Array(2001, 1, 1, 2010, 1, 1, YEARS, 2, 5), + Array(2001, 1, 1, 2010, 1, 1, MONTHS, 1, 108), + Array(2001, 1, 1, 2010, 1, 1, MONTHS, 2, 54), + Array(2001, 1, 1, 2010, 1, 1, WEEKS, 2, 235), + Array(2001, 1, 1, 2001, 10, 1, DAYS, 10, 28), + Array(2001, 1, 1, 2001, 10, 1, HOURS, 10, 656), + Array(2001, 1, 1, 2001, 10, 1, MINUTES, 10, 39306), + Array(2001, 1, 1, 2001, 1, 3, SECONDS, 1000, 173) ) } - + @Test(dataProvider = "datesRangeDP") - def testDateRangeInYears(startYear: Int, startMonth: Int, startDay: Int, endYear: Int, endMonth: Int, endDay: Int, rangeType: DateRangeType, step: Int, expectedSize: Int ) = { + def testDateRangeInYears( + startYear: Int, + startMonth: Int, + startDay: Int, + endYear: Int, + endMonth: Int, + endDay: Int, + rangeType: DateRangeType, + step: Int, + expectedSize: Int) = { val datesRange = calendar.datesRange - .startYear(startYear) - .startMonth(startMonth) - .startDay(startDay) - .stepEvery(step, rangeType) - .endYear(endYear) - .endMonth(endMonth) - .endDay(endDay) - .format(DateFormat.dd_MM_yyyy_H_m_s) - .asList + .startYear(startYear) + .startMonth(startMonth) + .startDay(startDay) + .stepEvery(step, rangeType) + .endYear(endYear) + .endMonth(endMonth) + .endDay(endDay) + .format(DateFormat.dd_MM_yyyy_H_m_s) + .asList assert(Math.abs(expectedSize - datesRange.length) <= 15) } @Test def testDateRangeWithStartEndDates() = { - val startDate = new DateTime(2001, 1, 1, 0, 0) - val endDate = new DateTime(2010, 1, 1, 0, 0) + val startDate = new DateTime(2001, 1, 1, 0, 0) + val endDate = new DateTime(2010, 1, 1, 0, 0) val datesRange = calendar.datesRange.startDate(startDate).stepEvery(1, YEARS).endDate(endDate).asList assertResult(9)(datesRange.length) assertDateRangeEqual(datesRange, 1, 1) } - @Test def testDateRangeInYearsWithException() = { try { @@ -286,7 +292,7 @@ class CalendarTestSuite extends BaseTestSuite { .endMonth(1) .endDay(1) .asList - }catch { + } catch { case e: IllegalArgumentException => assertResult("Step should be > 0")(e.getMessage) } } @@ -297,7 +303,8 @@ class CalendarTestSuite extends BaseTestSuite { .startYear(2001) .stepEvery(1, YEARS) .endYear(2010) - .format(dd_MM_yy).asStringsList + .format(dd_MM_yy) + .asStringsList assertResult(9)(dateRange.length) for (date <- dateRange) assert(date.matches("\\d{2}-\\w{2}-\\d{2}")) } @@ -308,9 +315,10 @@ class CalendarTestSuite extends BaseTestSuite { .startYear(2001) .stepEvery(1, YEARS) .endYear(2010) - .format(dd_MM_yy).asArray + .format(dd_MM_yy) + .asArray val currentMonth = DateTime.now.getMonthOfYear - val currentDay = DateTime.now.getDayOfMonth + val currentDay = DateTime.now.getDayOfMonth assertResult(9)(dateRange.length) assertDateRangeEqual(dateRange.toList, currentMonth, currentDay, format = "dd-MM-yy") } @@ -321,17 +329,22 @@ class CalendarTestSuite extends BaseTestSuite { .startYear(2001) .stepEvery(1, YEARS) .endYear(2010) - .format(dd_MM_yy).asStringsArray + .format(dd_MM_yy) + .asStringsArray assertResult(9)(dateRange.length) for (date <- dateRange) assert(date.matches("\\d{2}-\\w{2}-\\d{2}")) } val defaultFormat: String = "dd-MM-yyyy" - def assertDateRangeEqual(dateRange: List[DateTime], currentMonth: Int, currentDay: Int, format: String = defaultFormat): Unit = { + def assertDateRangeEqual( + dateRange: List[DateTime], + currentMonth: Int, + currentDay: Int, + format: String = defaultFormat): Unit = { for (i <- 1 to 8 by 1) { - val year: Int = ("200" + (i + 1)).toInt - val date: DateTime = dateRange(i) + val year: Int = ("200" + (i + 1)).toInt + val date: DateTime = dateRange(i) val expectedDate: DateTime = new DateTime(year, currentMonth, currentDay, 0, 0) assertResult(expectedDate.toString(defaultFormat))(date.toString(defaultFormat)) } @@ -340,52 +353,308 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testDateWithFormat() = { val format = dd_MM_yyyy - val year = calendar.year.toInt - val month = calendar.month.toInt - val day = calendar.day(year, month).toInt - val hour = calendar.hour12h.toInt + val year = calendar.year.toInt + val month = calendar.month.toInt + val day = calendar.day(year, month).toInt + val hour = calendar.hour12h.toInt val minute = calendar.minute.toInt val date = calendar.randomDate - .inYear(year) - .inMonth(month) - .inDay(day) - .inHour(hour) - .inMinute(minute) - .asString(format) + .inYear(year) + .inMonth(month) + .inDay(day) + .inHour(hour) + .inMinute(minute) + .asString(format) assertResult(new DateTime(year, month, day, hour, minute).toString(format.getFormat))(date) } @DataProvider - def dateWithPeriodDP():Array[Array[Any]] = { - Array(Array(0, 0, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(1, 0, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusYears(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(-1, 0, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusYears(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 1, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, -1, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), + def dateWithPeriodDP(): Array[Array[Any]] = { + Array[Array[Any]]( + Array(0, 0, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.toString(dd_MM_yyyy_SEMICOLON.getFormat)), + Array( + 1, + 0, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusYears(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + -1, + 0, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusYears(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 1, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + -1, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), Array(0, 0, 1, 0, 0, 0, 0, dd_MM_yyyy, DateTime.now.plusWeeks(1).toString(dd_MM_yyyy.getFormat)), - Array(0, 0, -1, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusWeeks(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, 1, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, -1, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, 0, 1, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusHours(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, 0, -1, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusHours(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, 0, 0, 1, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusMinutes(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(0, 0, 0, 0, 0, -1, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusMinutes(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(1, 1, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusYears(1).plusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(-1, -1, 0, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusYears(1).minusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(3, 3, 3, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusYears(3).plusMonths(3).plusWeeks(3).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(-1, -1, -1, 0, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusYears(1).minusMonths(1).minusWeeks(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(1, 1, 1, 1, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.plusYears(1).plusMonths(1).plusWeeks(1).plusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(-5, -5, -5, -5, 0, 0, 0, dd_MM_yyyy_SEMICOLON, DateTime.now.minusYears(5).minusMonths(5).minusWeeks(5).minusDays(5).toString(dd_MM_yyyy_SEMICOLON.getFormat)), - Array(1, 1, 1, 1, 1, 0, 0, dd_MM_yyyy_HH_SEMICOLON, DateTime.now.plusYears(1).plusMonths(1).plusWeeks(1).plusDays(1).plusHours(1).toString(dd_MM_yyyy_HH_SEMICOLON.getFormat)), - Array(-1, -1, -1, -1, -1, 0, 0, dd_MM_yyyy_HH_SEMICOLON, DateTime.now.minusYears(1).minusMonths(1).minusWeeks(1).minusDays(1).minusHours(1).toString(dd_MM_yyyy_HH_SEMICOLON.getFormat)), - Array(10, 10, 10, 10, 10, 10, 10, dd_MM_yyyy_HH_SEMICOLON, DateTime.now.plusYears(10).plusMonths(10).plusWeeks(10).plusDays(10).plusHours(10).plusMinutes(10).plusSeconds(10).toString(dd_MM_yyyy_HH_SEMICOLON.getFormat)), - Array(-100, -100, -100, -100, -100, -100, -10, dd_MM_yyyy_HH_SEMICOLON, DateTime.now.minusYears(100).minusMonths(100).minusWeeks(100).minusDays(100).minusHours(100).minusMinutes(100).minusSeconds(10).toString(dd_MM_yyyy_HH_SEMICOLON.getFormat)) + Array( + 0, + 0, + -1, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusWeeks(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + 1, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + -1, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + 0, + 1, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusHours(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + 0, + -1, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusHours(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + 0, + 0, + 1, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusMinutes(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 0, + 0, + 0, + 0, + 0, + -1, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusMinutes(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 1, + 1, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusYears(1).plusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + -1, + -1, + 0, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusYears(1).minusMonths(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 3, + 3, + 3, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusYears(3).plusMonths(3).plusWeeks(3).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + -1, + -1, + -1, + 0, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusYears(1).minusMonths(1).minusWeeks(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 1, + 1, + 1, + 1, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.plusYears(1).plusMonths(1).plusWeeks(1).plusDays(1).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + -5, + -5, + -5, + -5, + 0, + 0, + 0, + dd_MM_yyyy_SEMICOLON, + DateTime.now.minusYears(5).minusMonths(5).minusWeeks(5).minusDays(5).toString(dd_MM_yyyy_SEMICOLON.getFormat) + ), + Array( + 1, + 1, + 1, + 1, + 1, + 0, + 0, + dd_MM_yyyy_HH_SEMICOLON, + DateTime.now + .plusYears(1) + .plusMonths(1) + .plusWeeks(1) + .plusDays(1) + .plusHours(1) + .toString(dd_MM_yyyy_HH_SEMICOLON.getFormat) + ), + Array( + -1, + -1, + -1, + -1, + -1, + 0, + 0, + dd_MM_yyyy_HH_SEMICOLON, + DateTime.now + .minusYears(1) + .minusMonths(1) + .minusWeeks(1) + .minusDays(1) + .minusHours(1) + .toString(dd_MM_yyyy_HH_SEMICOLON.getFormat) + ), + Array( + 10, + 10, + 10, + 10, + 10, + 10, + 10, + dd_MM_yyyy_HH_SEMICOLON, + DateTime.now + .plusYears(10) + .plusMonths(10) + .plusWeeks(10) + .plusDays(10) + .plusHours(10) + .plusMinutes(10) + .plusSeconds(10) + .toString(dd_MM_yyyy_HH_SEMICOLON.getFormat) + ), + Array( + -100, + -100, + -100, + -100, + -100, + -100, + -10, + dd_MM_yyyy_HH_SEMICOLON, + DateTime.now + .minusYears(100) + .minusMonths(100) + .minusWeeks(100) + .minusDays(100) + .minusHours(100) + .minusMinutes(100) + .minusSeconds(10) + .toString(dd_MM_yyyy_HH_SEMICOLON.getFormat) + ) ) } @Test(dataProvider = "dateWithPeriodDP") - def testRelativeDate(year: Int, month: Int, week: Int, day: Int, hour: Int, minute: Int, second: Int, format: DateFormat, expectedDate: String) = { - val date = calendar.relativeDate.years(year).months(month).weeks(week).days(day).hours(hour).minutes(minute).seconds(second).asString(format) + def testRelativeDate( + year: Int, + month: Int, + week: Int, + day: Int, + hour: Int, + minute: Int, + second: Int, + format: DateFormat, + expectedDate: String) = { + val date = calendar.relativeDate + .years(year) + .months(month) + .weeks(week) + .days(day) + .hours(hour) + .minutes(minute) + .seconds(second) + .asString(format) if (debugEnabled) logger.debug("Testing random date with dateWithPeriod method: " + date) assertResult(expectedDate)(date) } @@ -393,14 +662,14 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testRelativeDateTomorrow() = { val expectedDate = DateTime.now.plusDays(1) - val date = calendar.relativeDate.tomorrow().asDate() + val date = calendar.relativeDate.tomorrow().asDate() assertResult(expectedDate.toString(defaultFormat))(date.toString(defaultFormat)) } @Test def testRelativeDateYesterday() = { val expectedDate = DateTime.now.minusDays(1).toString(defaultFormat) - val date = calendar.relativeDate.yesterday().asDate() + val date = calendar.relativeDate.yesterday().asDate() assertResult(expectedDate)(date.toString(defaultFormat)) } @@ -413,15 +682,15 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testRelativeDateCustomTimeZone() = { val expectedDate = DateTime.now(DateTimeZone.UTC) - val date = calendar.relativeDate(DateTimeZone.UTC).asDate() + val date = calendar.relativeDate(DateTimeZone.UTC).asDate() assertResult(expectedDate.toString(defaultFormat))(date.toString(defaultFormat)) } @Test def testRelativeDateWithCustomInitialDate() = { val expectedDate: DateTime = DateTime.now().plusDays(2) - val initialDate: DateTime = DateTime.now().plusDays(1) - val date = calendar.relativeDate(initialDate).tomorrow().asDate() + val initialDate: DateTime = DateTime.now().plusDays(1) + val date = calendar.relativeDate(initialDate).tomorrow().asDate() assertResult(expectedDate.toString(defaultFormat))(date.toString(defaultFormat)) } @@ -429,7 +698,7 @@ class CalendarTestSuite extends BaseTestSuite { def testRandomDateFromDateRange() = { val randomDate = calendar.datesRange.getRandomDate val startPoint = DateTime.now() - val endPoint = DateTime.now().plusYears(1) + val endPoint = DateTime.now().plusYears(1) assert(randomDate.isAfter(startPoint)) assert(randomDate.isBefore(endPoint)) } @@ -437,9 +706,9 @@ class CalendarTestSuite extends BaseTestSuite { @Test def testRandomDateStringFromDateRange() = { val randomDateString = calendar.datesRange.format(DateFormat.yyyy_MM_dd).getRandomDateString - val randomDate = DateTime.parse(randomDateString) - val startPoint = DateTime.now() - val endPoint = DateTime.now().plusYears(1) + val randomDate = DateTime.parse(randomDateString) + val startPoint = DateTime.now() + val endPoint = DateTime.now().plusYears(1) assert(randomDate.isAfter(startPoint)) assert(randomDate.isBefore(endPoint)) } diff --git a/src/test/scala/fabricator/ContactTestSuite.scala b/src/test/scala/fabricator/ContactTestSuite.scala index 33ae507..3fec18c 100644 --- a/src/test/scala/fabricator/ContactTestSuite.scala +++ b/src/test/scala/fabricator/ContactTestSuite.scala @@ -1,40 +1,40 @@ package fabricator +import org.testng.annotations.{DataProvider, Test} + import com.github.nscala_time.time.Imports._ + import fabricator.enums.DateFormat -import org.testng.annotations.{DataProvider, Test} class ContactTestSuite extends BaseTestSuite { - lazy val firstNameList: Array[String] = util.getArrayFromJson("first_name") - lazy val lastNameList: Array[String] = util.getArrayFromJson("last_name") - lazy val prefixList: Array[String] = util.getArrayFromJson("prefix") - lazy val suffixList: Array[String] = util.getArrayFromJson("suffix") + lazy val firstNameList: Array[String] = util.getArrayFromJson("first_name") + lazy val lastNameList: Array[String] = util.getArrayFromJson("last_name") + lazy val prefixList: Array[String] = util.getArrayFromJson("prefix") + lazy val suffixList: Array[String] = util.getArrayFromJson("suffix") lazy val phoneFormatsList: Array[String] = util.getArrayFromJson("phone_formats") - lazy val streetNameList: Array[String] = util.getArrayFromJson("street_suffix") - lazy val houseNumberList: Array[String] = util.getArrayFromJson("house_number") - lazy val appNumberList: Array[String] = util.getArrayFromJson("app_number") - lazy val postcodeList: Array[String] = util.getArrayFromJson("postcode") - lazy val countryList: Array[String] = util.getArrayFromJson("country") - lazy val stateList: Array[String] = util.getArrayFromJson("state") - lazy val stateAbbrList: Array[String] = util.getArrayFromJson("state_abbr") - lazy val cityPrefixList: Array[String] = util.getArrayFromJson("city_prefix") - lazy val citySuffixList: Array[String] = util.getArrayFromJson("city_suffix") - lazy val companyList: Array[String] = util.getArrayFromJson("company_suffix") - lazy val religionList: Array[String] = util.getArrayFromJson("religion") - lazy val zodiacList: Array[String] = util.getArrayFromJson("zodiac") - lazy val bloodTypeList: Array[String] = util.getArrayFromJson("blood_type") - lazy val occupationList: Array[String] = util.getArrayFromJson("occupation") + lazy val streetNameList: Array[String] = util.getArrayFromJson("street_suffix") + lazy val houseNumberList: Array[String] = util.getArrayFromJson("house_number") + lazy val appNumberList: Array[String] = util.getArrayFromJson("app_number") + lazy val postcodeList: Array[String] = util.getArrayFromJson("postcode") + lazy val countryList: Array[String] = util.getArrayFromJson("country") + lazy val stateList: Array[String] = util.getArrayFromJson("state") + lazy val stateAbbrList: Array[String] = util.getArrayFromJson("state_abbr") + lazy val cityPrefixList: Array[String] = util.getArrayFromJson("city_prefix") + lazy val citySuffixList: Array[String] = util.getArrayFromJson("city_suffix") + lazy val companyList: Array[String] = util.getArrayFromJson("company_suffix") + lazy val religionList: Array[String] = util.getArrayFromJson("religion") + lazy val zodiacList: Array[String] = util.getArrayFromJson("zodiac") + lazy val bloodTypeList: Array[String] = util.getArrayFromJson("blood_type") + lazy val occupationList: Array[String] = util.getArrayFromJson("occupation") @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customContact = fabricator.Contact(lang) assert(customContact != null) } @@ -50,7 +50,7 @@ class ContactTestSuite extends BaseTestSuite { val suffix = contact.suffix assert(suffixList.contains(suffix)) } - + @Test def testFirstName() = { val name = contact.firstName @@ -78,13 +78,13 @@ class ContactTestSuite extends BaseTestSuite { prefixList.contains(nameWithPrefix.split(" ")(0)) firstNameList.contains(nameWithPrefix.split(" ")(1)) lastNameList.contains(nameWithPrefix.split(" ")(2)) - //with suffix + // with suffix val nameWithSuffix = contact.fullName(setPrefix = false, setSuffix = true) if (debugEnabled) logger.debug("Checking full name value " + nameWithSuffix) firstNameList.contains(nameWithSuffix.split(" ")(0)) lastNameList.contains(nameWithSuffix.split(" ")(1)) suffixList.contains(nameWithSuffix.split(" ")(2)) - //with prefix and suffix + // with prefix and suffix val nameWithPrefixAndSuffix = contact.fullName(setPrefix = true, setSuffix = true) if (debugEnabled) logger.debug("Checking full name value " + nameWithPrefixAndSuffix) prefixList.contains(nameWithPrefixAndSuffix.split(" ")(0)) @@ -123,7 +123,7 @@ class ContactTestSuite extends BaseTestSuite { @Test def testhouseNumber() = { - val houseNumber = contact.houseNumber + val houseNumber = contact.houseNumber val reversedHouseNumber = houseNumber.replaceAll("[0-9]", "#") if (debugEnabled) logger.debug("Checking houseNumber value " + houseNumber) assert(houseNumberList.contains(reversedHouseNumber)) @@ -132,7 +132,7 @@ class ContactTestSuite extends BaseTestSuite { @Test def testApartmentNumber() = { val apartmentNumber = contact.apartmentNumber - val reversedApp = apartmentNumber.replaceAll("[0-9]", "#") + val reversedApp = apartmentNumber.replaceAll("[0-9]", "#") if (debugEnabled) logger.debug("Checking apartmentNumber value " + apartmentNumber) assert(appNumberList.contains(reversedApp)) } @@ -150,12 +150,12 @@ class ContactTestSuite extends BaseTestSuite { @Test def testPostcode() = { - val postCode = contact.postcode + val postCode = contact.postcode val reversedPostCode = postCode.replaceAll("[0-9]", "#") if (debugEnabled) logger.debug("Checking postCode value " + postCode) assert(postcodeList.contains(reversedPostCode)) } - + @Test def testCountry() = { val country = contact.country @@ -176,23 +176,20 @@ class ContactTestSuite extends BaseTestSuite { if (debugEnabled) logger.debug("Checking stateAbbr value " + stateAbbr) assert(stateAbbrList.contains(stateAbbr)) } - + @Test def testCity() = { val city = contact.city if (debugEnabled) logger.debug("Checking city value " + city) var prefixAvailability = 0 var suffixAvailability = 0 - for (prefix <- cityPrefixList){ + for (prefix <- cityPrefixList) if (city.contains(prefix)) prefixAvailability = prefixAvailability + 1 - } - for (suffix <- citySuffixList){ + for (suffix <- citySuffixList) if (city.contains(suffix)) suffixAvailability = suffixAvailability + 1 - } assert(prefixAvailability >= 1) assert(suffixAvailability >= 1) } - @Test def testCompany() = { @@ -202,28 +199,24 @@ class ContactTestSuite extends BaseTestSuite { } @DataProvider(name = "birthdayDP") - def birthdayDP(): Array[Array[Any]] = { - Array(Array(0), - Array(10), - Array(25), - Array(50), - Array(100), - Array(1000) - ) + def birthdayDP(): Array[Array[Int]] = { + Array(Array(0), Array(10), Array(25), Array(50), Array(100), Array(1000)) } @Test(dataProvider = "birthdayDP") def testBirthDay(age: Int) = { - if (debugEnabled) logger - .debug("Checking when is the birthday of an " + age + " years old. It's " + contact.birthday(age)) - val birthDate = contact.birthday(age) - val currentDay = DateTimeFormat.forPattern("dd-MM-yyyy").print(DateTime.now - age.years) + if (debugEnabled) + logger + .debug("Checking when is the birthday of an " + age + " years old. It's " + contact.birthday(age)) + val birthDate = contact.birthday(age) + val currentDay = DateTimeFormat.forPattern("dd-MM-yyyy").print(DateTime.now() - age.years) assert(birthDate == currentDay) } @DataProvider(name = "birthdayWithFormatsDP") def birthdayWithFormatsDP(): Array[Array[Any]] = { - Array(Array(21, DateFormat.dd_mm_yyyy_SEMICOLON), + Array[Array[Any]]( + Array(21, DateFormat.dd_mm_yyyy_SEMICOLON), Array(25, DateFormat.dd_mm_yyyy_SEMICOLON), Array(40, DateFormat.dd_mm_yyyy_SEMICOLON), Array(50, DateFormat.dd_MM_yyyy_SEMICOLON), @@ -243,11 +236,14 @@ class ContactTestSuite extends BaseTestSuite { @Test(dataProvider = "birthdayWithFormatsDP") def testBirthDayWithFormat(age: Int, format: DateFormat) = { - if (debugEnabled) logger - .debug("Checking when is the birthday of an " + age + " years old and format " + format + " . It's " + contact - .birthday(age, format)) - val birthDate = contact.birthday(age, format) - val currentDay = DateTimeFormat.forPattern(format.getFormat).print(DateTime.now - age.years) + if (debugEnabled) + logger + .debug( + "Checking when is the birthday of an " + age + " years old and format " + format + " . It's " + contact + .birthday(age, format) + ) + val birthDate = contact.birthday(age, format) + val currentDay = DateTimeFormat.forPattern(format.getFormat).print(DateTime.now() - age.years) assert(birthDate == currentDay) } @@ -257,7 +253,7 @@ class ContactTestSuite extends BaseTestSuite { if (debugEnabled) logger.debug("Testing random bsn number : " + bsn) assert(bsn < 999999999 && bsn >= 9999999) var sum: Int = -1 * bsn % 10 - for ( multiplier <- 2 to 100; if bsn > 0 ) { + for (multiplier <- 2 to 100 if bsn > 0) { bsn = bsn / 10 val value = bsn % 10 sum = sum + (multiplier * value) @@ -280,7 +276,7 @@ class ContactTestSuite extends BaseTestSuite { } @DataProvider(name = "zodiacDP") - def zodiacDP(): Array[Array[Any]] = { + def zodiacDP(): Array[Array[String]] = { Array( Array("22-12-2001", "Capricorn"), Array("10-01-2001", "Capricorn"), @@ -333,7 +329,7 @@ class ContactTestSuite extends BaseTestSuite { if (debugEnabled) logger.debug("Testing random height in cm " + contact.height(cm = true)) if (debugEnabled) logger.debug("Testing random height in m " + contact.height(cm = false)) val heightInCm = contact.height(cm = true).split(" ")(0).toDouble - val heightInM = contact.height(cm = false).split(" ")(0).toInt + val heightInM = contact.height(cm = false).split(" ")(0).toInt assert(heightInCm >= 1.50 && heightInCm <= 2.20) assert(heightInM >= 150 && heightInM <= 220) } diff --git a/src/test/scala/fabricator/FileTestSuite.scala b/src/test/scala/fabricator/FileTestSuite.scala index ef54580..7e4fa17 100644 --- a/src/test/scala/fabricator/FileTestSuite.scala +++ b/src/test/scala/fabricator/FileTestSuite.scala @@ -1,80 +1,81 @@ - - package fabricator import java.io.File +import org.testng.annotations.{AfterMethod, AfterTest, DataProvider, Test} + +import com.github.tototoshi.csv.defaultCSVFormat import com.github.tototoshi.csv.CSVReader + import fabricator.enums.{CsvValueCode, FileType, MimeType} -import org.testng.annotations.{AfterMethod, AfterTest, DataProvider, Test} class FileTestSuite extends BaseTestSuite { - protected val csvFilePath: String = "generatedFiles/result.csv" + protected val csvFilePath: String = "generatedFiles/result.csv" protected val imageFilePath: String = "generatedFiles/result.png" - protected var fileObject: File = null + protected var fileObject: File = null // File extensions private lazy val audioExtensionList = util.getArrayFromJson("audio_file_extensions") private lazy val imageExtensionList = util.getArrayFromJson("image_file_extensions") - private lazy val textExtensionList = util.getArrayFromJson("text_file_extensions") - private lazy val docExtensionList = util.getArrayFromJson("document_file_extensions") + private lazy val textExtensionList = util.getArrayFromJson("text_file_extensions") + private lazy val docExtensionList = util.getArrayFromJson("document_file_extensions") private lazy val videoExtensionList = util.getArrayFromJson("video_file_extensions") - //Mime types + // Mime types private lazy val applicationMimeTypes = util.getArrayFromJson("application_mime_types") - private lazy val audioMimeTypes = util.getArrayFromJson("audio_mime_types") - private lazy val imageMimeTypes = util.getArrayFromJson("image_mime_types") - private lazy val messageMimeTypes = util.getArrayFromJson("message_mime_types") - private lazy val modelMimeTypes = util.getArrayFromJson("model_mime_types") - private lazy val multipartMimeTypes = util.getArrayFromJson("multipart_mime_types") - private lazy val textMimeTypes = util.getArrayFromJson("text_mime_types") - private lazy val videoMimeTypes = util.getArrayFromJson("video_mime_types") - private lazy val codes = Array(CsvValueCode.OCCUPATION, - CsvValueCode.VISA, - CsvValueCode.MASTER, - CsvValueCode.IBAN, - CsvValueCode.BIC, - CsvValueCode.URL, - CsvValueCode.IP, - CsvValueCode.MACADDRESS, - CsvValueCode.UUID, - CsvValueCode.COLOR, - CsvValueCode.TWITTER, - CsvValueCode.HASHTAG, - CsvValueCode.FACEBOOK, - CsvValueCode.GOOGLE_ANALYTICS, - CsvValueCode.ALTITUDE, - CsvValueCode.DEPTH, - CsvValueCode.LATITUDE, - CsvValueCode.LONGITUDE, - CsvValueCode.COORDINATES, - CsvValueCode.GEOHASH, - CsvValueCode.APPLE_TOKEN, - CsvValueCode.ANDROID, - CsvValueCode.POSTCODE, - CsvValueCode.WINDOWS7TOKEN, - CsvValueCode.WINDOWS8TOKEN, - CsvValueCode.WORD, - CsvValueCode.SENTENCE, - CsvValueCode.INTEGER, - CsvValueCode.INTEGER, - CsvValueCode.DOUBLE, - CsvValueCode.HASH, - CsvValueCode.GUID, - CsvValueCode.TIME, - CsvValueCode.DATE, - CsvValueCode.NAME) - - - + private lazy val audioMimeTypes = util.getArrayFromJson("audio_mime_types") + private lazy val imageMimeTypes = util.getArrayFromJson("image_mime_types") + private lazy val messageMimeTypes = util.getArrayFromJson("message_mime_types") + private lazy val modelMimeTypes = util.getArrayFromJson("model_mime_types") + private lazy val multipartMimeTypes = util.getArrayFromJson("multipart_mime_types") + private lazy val textMimeTypes = util.getArrayFromJson("text_mime_types") + private lazy val videoMimeTypes = util.getArrayFromJson("video_mime_types") + + private lazy val codes = Array( + CsvValueCode.OCCUPATION, + CsvValueCode.VISA, + CsvValueCode.MASTER, + CsvValueCode.IBAN, + CsvValueCode.BIC, + CsvValueCode.URL, + CsvValueCode.IP, + CsvValueCode.MACADDRESS, + CsvValueCode.UUID, + CsvValueCode.COLOR, + CsvValueCode.TWITTER, + CsvValueCode.HASHTAG, + CsvValueCode.FACEBOOK, + CsvValueCode.GOOGLE_ANALYTICS, + CsvValueCode.ALTITUDE, + CsvValueCode.DEPTH, + CsvValueCode.LATITUDE, + CsvValueCode.LONGITUDE, + CsvValueCode.COORDINATES, + CsvValueCode.GEOHASH, + CsvValueCode.APPLE_TOKEN, + CsvValueCode.ANDROID, + CsvValueCode.POSTCODE, + CsvValueCode.WINDOWS7TOKEN, + CsvValueCode.WINDOWS8TOKEN, + CsvValueCode.WORD, + CsvValueCode.SENTENCE, + CsvValueCode.INTEGER, + CsvValueCode.INTEGER, + CsvValueCode.DOUBLE, + CsvValueCode.HASH, + CsvValueCode.GUID, + CsvValueCode.TIME, + CsvValueCode.DATE, + CsvValueCode.NAME + ) @Test - def testCustomConstructor() { + def testCustomConstructor() = { val customFile = fabricator.FileGenerator("us") assert(Option(customFile).isDefined) } @Test - def testImage() { + def testImage() = { file.image(200, 300, imageFilePath) val fileOnADrive: File = new File(imageFilePath) fileObject = fileOnADrive @@ -83,7 +84,7 @@ class FileTestSuite extends BaseTestSuite { } @Test - def testCsv() { + def testCsv() = { file.csvBuilder.build() val fileOnADrive: File = new File(csvFilePath) fileObject = fileOnADrive @@ -92,16 +93,18 @@ class FileTestSuite extends BaseTestSuite { } @Test - def testCustomCsv() { - val codes = Array(CsvValueCode.FIRST_NAME, - CsvValueCode.LAST_NAME, - CsvValueCode.BIRTHDAY, - CsvValueCode.EMAIL, - CsvValueCode.PHONE, - CsvValueCode.ADDRESS, - CsvValueCode.BSN, - CsvValueCode.WEIGHT, - CsvValueCode.HEIGHT) + def testCustomCsv() = { + val codes = Array( + CsvValueCode.FIRST_NAME, + CsvValueCode.LAST_NAME, + CsvValueCode.BIRTHDAY, + CsvValueCode.EMAIL, + CsvValueCode.PHONE, + CsvValueCode.ADDRESS, + CsvValueCode.BSN, + CsvValueCode.WEIGHT, + CsvValueCode.HEIGHT + ) file.csvBuilder .withCodes(codes) .withNumberOfRows(10) @@ -110,15 +113,16 @@ class FileTestSuite extends BaseTestSuite { val fileOnADrive: File = new File(csvFilePath) fileObject = fileOnADrive assert(fileObject.exists()) - val line = CSVReader.open(fileOnADrive).all() + val line = CSVReader.open(fileOnADrive).all() val firstNameList: Array[String] = util.getArrayFromJson("first_name") assert(firstNameList.contains(line(1).headOption.getOrElse(""))) } @Test - def testCsvWithCustomDelimiter() { + def testCsvWithCustomDelimiter() = { val numberOfRows = 10 - file.csvBuilder.withCodes(codes) + file.csvBuilder + .withCodes(codes) .withNumberOfRows(10) .withDelimiter('|') .saveTo(csvFilePath) @@ -129,8 +133,8 @@ class FileTestSuite extends BaseTestSuite { fileObject = fileOnADrive assert(fileObject.exists()) // read file and confirm that correct data is present - val reader = CSVReader.open(fileOnADrive) - val lines = reader.all() + val reader = CSVReader.open(fileOnADrive) + val lines = reader.all() val numberOfRowsInFile = lines.length assertResult(numberOfRows + 1)(numberOfRowsInFile) // assert that inserted data is correct @@ -140,47 +144,47 @@ class FileTestSuite extends BaseTestSuite { } @Test - def testCsvWithCustomSequence() { - val values = Array(alpha.randomInt, alpha.randomDouble, calendar.ampm, null) + def testCsvWithCustomSequence() = { + val values = Array[Any](alpha.randomInt, alpha.randomDouble, calendar.ampm, null) val numberOfRows = 10 file.csvBuilder - .withNumberOfRows(numberOfRows) - .withCustomCodes(values) - .saveTo(csvFilePath) - .build() + .withNumberOfRows(numberOfRows) + .withCustomCodes(values) + .saveTo(csvFilePath) + .build() // check that file exists val fileOnADrive: File = new File(csvFilePath) fileObject = fileOnADrive assert(fileObject.exists()) // read file and confirm that correct data is present - val reader = CSVReader.open(fileOnADrive) - val lines = reader.all() + val reader = CSVReader.open(fileOnADrive) + val lines = reader.all() val numberOfRowsInFile = lines.length assertResult(numberOfRows + 1)(numberOfRowsInFile) // assert that inserted data is correct val expectedTitles = Array("Integer number", "Double number", "String", "") - val titles = lines.head + val titles = lines.head for (title <- expectedTitles) assert(titles.contains(title)) } @Test - def testCsvWithTitle() { - val titles = Array("first_column", "second_column", "third_column", "fourth_column") - val values = Array(alpha.randomInt, CsvValueCode.ANDROID, "10", null) + def testCsvWithTitle() = { + val titles = Array("first_column", "second_column", "third_column", "fourth_column") + val values = Array[Any](alpha.randomInt, CsvValueCode.ANDROID, "10", null) val numberOfRows = 10 file.csvBuilder - .withNumberOfRows(numberOfRows) - .withCustomCodes(values) - .withTitles(titles) - .build() + .withNumberOfRows(numberOfRows) + .withCustomCodes(values) + .withTitles(titles) + .build() // check that file exists val fileOnADrive: File = new File(csvFilePath) fileObject = fileOnADrive assert(fileObject.exists()) // read file and confirm that correct data is present - val reader = CSVReader.open(fileOnADrive) - val lines = reader.all() - val actualTitles = lines.headOption.getOrElse(List[String]()) + val reader = CSVReader.open(fileOnADrive) + val lines = reader.all() + val actualTitles = lines.headOption.getOrElse(List[String]()) val numberOfRowsInFile = lines.length for (title <- actualTitles) assert(titles.contains(title)) assertResult(numberOfRows + 1)(numberOfRowsInFile) @@ -189,21 +193,18 @@ class FileTestSuite extends BaseTestSuite { @DataProvider def sizeDP(): Array[Array[Any]] = { - Array(Array(100, 3000, "path"), - Array(10000, 300, "path"), - Array(10000, 3000, "path") - ) + Array[Array[Any]](Array(100, 3000, "path"), Array(10000, 300, "path"), Array(10000, 3000, "path")) } - @Test(expectedExceptions = Array(classOf[IllegalArgumentException]), dataProvider = "sizeDP") - def testImageFileWithExceptionForSize(width: Int, height: Int, path: String) { + def testImageFileWithExceptionForSize(width: Int, height: Int, path: String) = { file.image(width, height, path) } @DataProvider def fileTypeDP(): Array[Array[Any]] = { - Array(Array(FileType.AUDIO, audioExtensionList), + Array[Array[Any]]( + Array(FileType.AUDIO, audioExtensionList), Array(FileType.IMAGE, imageExtensionList), Array(FileType.TEXT, textExtensionList), Array(FileType.DOCUMENT, docExtensionList), @@ -212,15 +213,15 @@ class FileTestSuite extends BaseTestSuite { } @Test(dataProvider = "fileTypeDP") - def testFileExtension(fileType: FileType, expectedList:Array[String]) { + def testFileExtension(fileType: FileType, expectedList: Array[String]) = { val extension = file.fileExtension(fileType) assert(expectedList.contains(extension)) } @Test(dataProvider = "fileTypeDP") - def testFileName(fileType: FileType, expectedTypeArray: Array[String]) { - val fileName = file.fileName(fileType) - val name = fileName.split("\\.")(0) + def testFileName(fileType: FileType, expectedTypeArray: Array[String]) = { + val fileName = file.fileName(fileType) + val name = fileName.split("\\.")(0) val fileExtension = fileName.split("\\.")(1) assert(expectedTypeArray.contains(fileExtension)) assert(fileName.length > 0) @@ -228,34 +229,37 @@ class FileTestSuite extends BaseTestSuite { } @Test - def testRandomFileExtension() { + def testRandomFileExtension() = { val fileExtension = file.fileExtension - assert(audioExtensionList.contains(fileExtension) || - imageExtensionList.contains(fileExtension) || - textExtensionList.contains(fileExtension) || - docExtensionList.contains(fileExtension) || - videoExtensionList.contains(fileExtension) + assert( + audioExtensionList.contains(fileExtension) || + imageExtensionList.contains(fileExtension) || + textExtensionList.contains(fileExtension) || + docExtensionList.contains(fileExtension) || + videoExtensionList.contains(fileExtension) ) } @Test - def testFileNameWithRandomExtension() { - val fileName = file.fileName - val name = fileName.split("\\.")(0) + def testFileNameWithRandomExtension() = { + val fileName = file.fileName + val name = fileName.split("\\.")(0) val fileExtension = fileName.split("\\.")(1) assert(name.length > 0) - assert(audioExtensionList.contains(fileExtension) || - imageExtensionList.contains(fileExtension) || - textExtensionList.contains(fileExtension) || - docExtensionList.contains(fileExtension) || - videoExtensionList.contains(fileExtension) + assert( + audioExtensionList.contains(fileExtension) || + imageExtensionList.contains(fileExtension) || + textExtensionList.contains(fileExtension) || + docExtensionList.contains(fileExtension) || + videoExtensionList.contains(fileExtension) ) } @DataProvider def mimeTypeDP(): Array[Array[Any]] = { - Array(Array(MimeType.APPLICATION, applicationMimeTypes), + Array[Array[Any]]( + Array(MimeType.APPLICATION, applicationMimeTypes), Array(MimeType.AUDIO, audioMimeTypes), Array(MimeType.IMAGE, imageMimeTypes), Array(MimeType.MESSAGE, messageMimeTypes), @@ -267,30 +271,30 @@ class FileTestSuite extends BaseTestSuite { } @Test(dataProvider = "mimeTypeDP") - def testMimeExtension(mimeType: MimeType, expectedList:Array[String]) { + def testMimeExtension(mimeType: MimeType, expectedList: Array[String]) = { val extension = file.mime_type(mimeType) assert(expectedList.contains(extension)) } @Test - def testRandomMimeExtension() { + def testRandomMimeExtension() = { val mimeType = file.mime_type - assert(applicationMimeTypes.contains(mimeType) || - audioMimeTypes.contains(mimeType) || - imageMimeTypes.contains(mimeType) || - messageMimeTypes.contains(mimeType) || - modelMimeTypes.contains(mimeType) || - multipartMimeTypes.contains(mimeType) || - textMimeTypes.contains(mimeType) || - videoMimeTypes.contains(mimeType) + assert( + applicationMimeTypes.contains(mimeType) || + audioMimeTypes.contains(mimeType) || + imageMimeTypes.contains(mimeType) || + messageMimeTypes.contains(mimeType) || + modelMimeTypes.contains(mimeType) || + multipartMimeTypes.contains(mimeType) || + textMimeTypes.contains(mimeType) || + videoMimeTypes.contains(mimeType) ) } @AfterMethod - def tearDown() { + def tearDown() = { logger.info("Deleting file") if (Option(fileObject).isDefined) fileObject.delete() } - } diff --git a/src/test/scala/fabricator/FinanceTestSuite.scala b/src/test/scala/fabricator/FinanceTestSuite.scala index 06f6292..a22120a 100644 --- a/src/test/scala/fabricator/FinanceTestSuite.scala +++ b/src/test/scala/fabricator/FinanceTestSuite.scala @@ -6,14 +6,12 @@ import org.testng.annotations.{DataProvider, Test} class FinanceTestSuite extends BaseTestSuite { @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customFinance = fabricator.Finance(lang) assert(customFinance != null) } @@ -45,10 +43,10 @@ class FinanceTestSuite extends BaseTestSuite { if (length < 8 || length > 9) { return false } - var pos = 0 + var pos = 0 var result = 0 for (i <- length to 0 by -1) { - if (pos < length){ + if (pos < length) { val addition = if (i != 1) bsn.charAt(pos).asDigit * i else bsn.charAt(pos).asDigit * i * -1 result = result + addition } @@ -65,7 +63,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(creditCards.length == 10) for (creditCard <- creditCards) assert(creditCard.length == 16) if (debugEnabled) logger.debug("Testing random masterCard : " + creditCard) - for ((card, index) <- creditCards.view.zipWithIndex) if (debugEnabled) logger.debug("Master Credit card #" + index + " is " + card) + for ((card, index) <- creditCards.view.zipWithIndex) + if (debugEnabled) logger.debug("Master Credit card #" + index + " is " + card) } @Test @@ -82,8 +81,10 @@ class FinanceTestSuite extends BaseTestSuite { for (visa <- visa15Cards) assert(visa.length() == 15) if (debugEnabled) logger.debug("Testing random 16 length Visa Card : " + visa16CreditCard) if (debugEnabled) logger.debug("Testing random 15 length Visa Card : " + visa15CreditCard) - for ((card, index) <- visa16Cards.view.zipWithIndex) if (debugEnabled) logger.debug("Visa Credit card #" + index + " is " + card) - for ((card, index) <- visa15Cards.view.zipWithIndex) if (debugEnabled) logger.debug("Visa Credit card #" + index + " is " + card) + for ((card, index) <- visa16Cards.view.zipWithIndex) + if (debugEnabled) logger.debug("Visa Credit card #" + index + " is " + card) + for ((card, index) <- visa15Cards.view.zipWithIndex) + if (debugEnabled) logger.debug("Visa Credit card #" + index + " is " + card) } @Test @@ -94,7 +95,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(amexCrediCards.length == 10) for (amex <- amexCrediCards) assert(amex.length == 16) if (debugEnabled) logger.debug("Testing random american express card: " + amexCreditCard) - for ((card, index) <- amexCrediCards.view.zipWithIndex) if (debugEnabled) logger.debug("american express card #" + index + " is " + card) + for ((card, index) <- amexCrediCards.view.zipWithIndex) + if (debugEnabled) logger.debug("american express card #" + index + " is " + card) } @Test @@ -105,7 +107,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(discoverCrediCards.length == 10) for (discover <- discoverCrediCards) assert(discover.length == 16) if (debugEnabled) logger.debug("Testing random discover card: " + discoverCreditCard) - for ((card, index) <- discoverCrediCards.view.zipWithIndex) if (debugEnabled) logger.debug("Discover Credit card #" + index + " is " + card) + for ((card, index) <- discoverCrediCards.view.zipWithIndex) + if (debugEnabled) logger.debug("Discover Credit card #" + index + " is " + card) } @Test @@ -116,7 +119,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(dinersCrediCards.length == 10) for (diners <- dinersCrediCards) assert(diners.length == 16) if (debugEnabled) logger.debug("Testing random diners card: " + dinersCreditCard) - for ((card, index) <- dinersCrediCards.view.zipWithIndex) if (debugEnabled) logger.debug("Diners Credit card #" + index + " is " + card) + for ((card, index) <- dinersCrediCards.view.zipWithIndex) + if (debugEnabled) logger.debug("Diners Credit card #" + index + " is " + card) } @Test @@ -127,7 +131,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(jcbCrediCards.length == 10) for (jcb <- jcbCrediCards) assert(jcb.length == 16) if (debugEnabled) logger.debug("Testing random jcb card: " + jcbCreditCard) - for ((card, index) <- jcbCrediCards.view.zipWithIndex) if (debugEnabled) logger.debug("JCB Credit card #" + index + " is " + card) + for ((card, index) <- jcbCrediCards.view.zipWithIndex) + if (debugEnabled) logger.debug("JCB Credit card #" + index + " is " + card) } @Test @@ -138,7 +143,8 @@ class FinanceTestSuite extends BaseTestSuite { assert(voyagerCrediCards.length == 10) for (voyager <- voyagerCrediCards) assert(voyager.length == 15) if (debugEnabled) logger.debug("Testing random voyager card: " + voyagerCreditCard) - for ((card, index) <- voyagerCrediCards.view.zipWithIndex) if (debugEnabled) logger.debug("Voyager Credit card #" + index + " is " + card) + for ((card, index) <- voyagerCrediCards.view.zipWithIndex) + if (debugEnabled) logger.debug("Voyager Credit card #" + index + " is " + card) } @Test diff --git a/src/test/scala/fabricator/InternetTestSuite.scala b/src/test/scala/fabricator/InternetTestSuite.scala index 4003cc4..a0df4fe 100644 --- a/src/test/scala/fabricator/InternetTestSuite.scala +++ b/src/test/scala/fabricator/InternetTestSuite.scala @@ -3,30 +3,29 @@ package fabricator import java.net.URL import java.nio.charset.Charset -import com.sun.jndi.toolkit.url.Uri -import org.testng.AssertJUnit.assertTrue import org.testng.annotations.{DataProvider, Test} +import org.testng.AssertJUnit.assertTrue + +import com.sun.jndi.toolkit.url.Uri import scala.collection.mutable class InternetTestSuite extends BaseTestSuite { @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customInternet = fabricator.Internet(lang) assert(customInternet != null) } @Test def testDefaultUrl() = { - val url = internet.urlBuilder.toString() + val url = internet.urlBuilder.toString() val splitArray: Array[String] = url.split("/") assert(url.matches("^(.*:)//([A-Za-z0-9\\-\\.]+)(:[0-9]+)?(.*)$")) assertResult("http:")(splitArray(0)) @@ -35,7 +34,7 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUrlAsUri() = { - val url = internet.urlBuilder.host("test.ru").toUri + val url = internet.urlBuilder.host("test.ru").toUri val expectedUrl = new Uri("http://test.ru/getEntity?q=test") assertResult(expectedUrl.getScheme)(url.getScheme) assertResult(expectedUrl.getHost)(url.getHost) @@ -46,14 +45,14 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUrlAsURL() = { - val url = internet.urlBuilder.host("test.ru").toUrl + val url = internet.urlBuilder.host("test.ru").toUrl val expectedUrl = new URL("http://test.ru/getEntity?q=test") assertResult(expectedUrl)(url) } @Test def testUrlWithCustomProtocol() = { - val url = internet.urlBuilder.scheme("https").toString() + val url = internet.urlBuilder.scheme("https").toString() val splitArray: Array[String] = url.split("/") assert(url.matches("^(.*:)//([A-Za-z0-9\\-\\.]+)(:[0-9]+)?(.*)$")) assertResult("https:")(splitArray(0)) @@ -62,7 +61,7 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUlrWithCustomHost() = { - val url = internet.urlBuilder.host("test.net").toString() + val url = internet.urlBuilder.host("test.net").toString() val splitArray: Array[String] = url.split("/") assert(url.matches("^(.*:)//([A-Za-z0-9\\-\\.]+)(:[0-9]+)?(.*)$")) assertResult("http:")(splitArray(0)) @@ -72,7 +71,7 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUrlWithCustomPort() = { - val url = internet.urlBuilder.host("test.net").port(8080).toString() + val url = internet.urlBuilder.host("test.net").port(8080).toString() val splitArray: Array[String] = url.split("/") assert(url.matches("^(.*:)//([A-Za-z0-9\\-\\.]+)(:[0-9]+)?(.*)$")) assertResult("http:")(splitArray(0)) @@ -82,7 +81,7 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUlrWithCustomPath() = { - val url = internet.urlBuilder.host("test.net").path("/customPath").toString() + val url = internet.urlBuilder.host("test.net").path("/customPath").toString() val splitArray: Array[String] = url.split("/") assert(url.matches("^(.*:)//([A-Za-z0-9\\-\\.]+)(:[0-9]+)?(.*)$")) assertResult("http:")(splitArray(0)) @@ -92,7 +91,8 @@ class InternetTestSuite extends BaseTestSuite { @DataProvider(name = "urlCustomParams") def urlCustomParams() = { - Array(Array(mutable.Map[String, Any]("q" -> "test"), "?q=test"), + Array( + Array(mutable.Map[String, Any]("q" -> "test"), "?q=test"), Array(mutable.Map[String, Any]("q" -> "test", "test" -> "hello"), "?q=test&test=hello"), Array(mutable.Map[String, Any]("q" -> "test", "name" -> "Josh Lennon"), "?q=test&name=Josh+Lennon"), Array(mutable.Map[String, Any]("q" -> true), "?q=true"), @@ -115,7 +115,11 @@ class InternetTestSuite extends BaseTestSuite { @Test def testUrlEncodeAsCharset() = { - val url = internet.urlBuilder.host("test.com").params(mutable.Map("q"->"test 123")).encodeAs(Charset.forName("UTF-8")).toString() + val url = internet.urlBuilder + .host("test.com") + .params(mutable.Map("q" -> "test 123")) + .encodeAs(Charset.forName("UTF-8")) + .toString() assertResult("http://test.com/getEntity%3Fq%3Dtest%2B123")(url) } @@ -132,9 +136,8 @@ class InternetTestSuite extends BaseTestSuite { assert(ip != "0.0.0.0") assert(ip != "255.255.255.255") val ipValues = ip.split("\\.") - for (i <- 0 to ipValues.size - 1) { + for (i <- 0 to ipValues.size - 1) assert(ipValues(i).toInt <= 256) - } } @Test @@ -167,12 +170,21 @@ class InternetTestSuite extends BaseTestSuite { @DataProvider(name = "colorVariations") def colorVariations() = { - Array(Array("hex", false, "^#[A-Fa-f0-9]{1,6}"), + Array( + Array("hex", false, "^#[A-Fa-f0-9]{1,6}"), Array("hex", true, "^#[A-Fa-f0-9]{1,6}"), Array("shorthex", false, "^#[A-Fa-f0-9]{1,6}"), Array("shorthex", true, "^#[A-Fa-f0-9]{1,6}"), - Array("rgb", true, "rgb\\(\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*\\)$"), - Array("rgb", false, "rgb\\(\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*\\)$") + Array( + "rgb", + true, + "rgb\\(\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*\\)$" + ), + Array( + "rgb", + false, + "rgb\\(\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*,\\s*((?:[0-2]?[0-9])?[0-9])\\s*\\)$" + ) ) } @@ -185,7 +197,10 @@ class InternetTestSuite extends BaseTestSuite { def testColor(codeType: String, grayscale: Boolean, regexMatch: String) = { for (i <- 1 to 10) { val color = internet.color(codeType, grayscale) - if (debugEnabled) logger.debug("Testing random " + codeType + " color with greyscale = " + grayscale + ". Color code is : " + color) + if (debugEnabled) + logger.debug( + "Testing random " + codeType + " color with greyscale = " + grayscale + ". Color code is : " + color + ) assert(color.matches(regexMatch), "Color " + color + " didn't match to regex : " + regexMatch) } } @@ -201,7 +216,7 @@ class InternetTestSuite extends BaseTestSuite { def testHashtag() = { val hashtag = internet.hashtag if (debugEnabled) logger.debug("Testing random hashtag account name : " + hashtag) - assertTrue("Hashtag: "+hashtag, hashtag.matches("#([A-Za-z0-9\\-\\_]+)")) + assertTrue("Hashtag: " + hashtag, hashtag.matches("#([A-Za-z0-9\\-\\_]+)")) } @Test @@ -230,5 +245,4 @@ class InternetTestSuite extends BaseTestSuite { assert(userName.matches("^[a-z-A-Z0-9_-]{3,30}$")) } - } diff --git a/src/test/scala/fabricator/LocationTestSuite.scala b/src/test/scala/fabricator/LocationTestSuite.scala index 9895206..10e5d40 100644 --- a/src/test/scala/fabricator/LocationTestSuite.scala +++ b/src/test/scala/fabricator/LocationTestSuite.scala @@ -1,33 +1,26 @@ package fabricator +import org.testng.annotations.{DataProvider, Test} + import com.spatial4j.core.context.SpatialContext import com.spatial4j.core.io.GeohashUtils -import org.testng.annotations.{DataProvider, Test} class LocationTestSuite extends BaseTestSuite { @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customLocation = fabricator.Location(lang) assert(Option(customLocation).isDefined) } - + @DataProvider(name = "altitudeDP") - def wordsCountDP():Array[Array[Any]]= { - Array(Array("10"), - Array("100"), - Array("1000"), - Array("4000"), - Array("10000"), - Array("100000") - ) + def wordsCountDP(): Array[Array[String]] = { + Array(Array("10"), Array("100"), Array("1000"), Array("4000"), Array("10000"), Array("100000")) } @Test @@ -89,8 +82,8 @@ class LocationTestSuite extends BaseTestSuite { @Test def testCoordinates() = { val coordinates = location.coordinates - val latitude = coordinates.split(",")(0) - val longitude = coordinates.split(",")(1) + val latitude = coordinates.split(",")(0) + val longitude = coordinates.split(",")(1) assert(latitude.toDouble >= -90 && latitude.toDouble < 90) assert(longitude.toDouble >= -180 && longitude.toDouble < 180) assert(latitude.split("\\.")(1).length == 5) @@ -100,8 +93,8 @@ class LocationTestSuite extends BaseTestSuite { @Test def testCoordinatesAccuracy() = { val coordinates = location.coordinates(2) - val latitude = coordinates.split(",")(0) - val longitude = coordinates.split(",")(1) + val latitude = coordinates.split(",")(0) + val longitude = coordinates.split(",")(1) assert(latitude.toDouble >= -90 && latitude.toDouble < 90) assert(longitude.toDouble >= -180 && longitude.toDouble < 180) assert(latitude.split("\\.")(1).length == 2) @@ -170,9 +163,9 @@ class LocationTestSuite extends BaseTestSuite { @Test def testGeoHashWithSpecificValues() = { - val latitude = location.latitude(2).toDouble - val longitude = location.longitude(2).toDouble - val geohash = location.geohash(latitude, longitude) + val latitude = location.latitude(2).toDouble + val longitude = location.longitude(2).toDouble + val geohash = location.geohash(latitude, longitude) val decodedValue = GeohashUtils.decode(geohash, SpatialContext.GEO) assert(Math.abs(decodedValue.getX - longitude) <= 0.2) assert(Math.abs(decodedValue.getY - latitude) <= 0.2) diff --git a/src/test/scala/fabricator/MobileTestSuite.scala b/src/test/scala/fabricator/MobileTestSuite.scala index 415f418..f5dbdeb 100644 --- a/src/test/scala/fabricator/MobileTestSuite.scala +++ b/src/test/scala/fabricator/MobileTestSuite.scala @@ -1,7 +1,8 @@ package fabricator +import java.util.Base64 + import org.testng.annotations.Test -import sun.misc.BASE64Decoder class MobileTestSuite extends BaseTestSuite { @@ -28,7 +29,7 @@ class MobileTestSuite extends BaseTestSuite { val windows8Id = mobile.wp8_anid2 if (debugEnabled) logger.debug("Testing random windows 8 ID : " + windows8Id) val expectedString = "0123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_" - val decodedString = new BASE64Decoder().decodeBuffer(windows8Id) + val decodedString = Base64.getDecoder.decode(windows8Id) for (symbol <- decodedString) assert(expectedString.contains(symbol)) } diff --git a/src/test/scala/fabricator/WordsTestSuite.scala b/src/test/scala/fabricator/WordsTestSuite.scala index f762941..59746b7 100644 --- a/src/test/scala/fabricator/WordsTestSuite.scala +++ b/src/test/scala/fabricator/WordsTestSuite.scala @@ -7,36 +7,29 @@ import scala.collection.mutable class WordsTestSuite extends BaseTestSuite { @DataProvider(name = "languageDp") - def languageDp(): Array[Array[Any]] = { - Array(Array("nl"), - Array("de") - ) + def languageDp(): Array[Array[String]] = { + Array(Array("nl"), Array("de")) } @Test(dataProvider = "languageDp") - def testCustomConstructor(lang: String) { + def testCustomConstructor(lang: String) = { val customWords = Option(fabricator.Words(lang)) assert(customWords.isDefined) } - + @DataProvider(name = "wordsCountDP") - def wordsCountDP():Array[Array[String]]= { - Array(Array("10"), - Array("100"), - Array("1000"), - Array("4000"), - Array("9500") - ) + def wordsCountDP(): Array[Array[String]] = { + Array(Array("10"), Array("100"), Array("1000"), Array("4000"), Array("9500")) } @Test - def testDefaultWords() { + def testDefaultWords() = { val wordsDefaultArray: Array[String] = words.words() if (debugEnabled) logger.debug("Getting words array generated with default length ") assert(wordsDefaultArray.length == 10) val inputSet: mutable.Set[String] = scala.collection.mutable.Set() - wordsDefaultArray.indices.foreach{ - index => inputSet.add(wordsDefaultArray(index)) + wordsDefaultArray.indices.foreach { index => + inputSet.add(wordsDefaultArray(index)) } assertResult(10)(inputSet.size) } @@ -45,7 +38,7 @@ class WordsTestSuite extends BaseTestSuite { def testWordsMaximumAmountException(): Unit = { words.words(100001) } - + @Test(dataProvider = "wordsCountDP") def testWords(count: String) = { if (debugEnabled) logger.debug("Getting words array generated with length = " + count) @@ -76,9 +69,11 @@ class WordsTestSuite extends BaseTestSuite { @Test(dataProvider = "wordsCountDP") def testTextCustomValue(length: String) = { val paragraph = words.paragraph(length.toInt) - if (debugEnabled) logger.debug("Testing sentence generation. Creating paragraph with chars length: " + length.toInt + "\n" + paragraph) + if (debugEnabled) + logger.debug( + "Testing sentence generation. Creating paragraph with chars length: " + length.toInt + "\n" + paragraph + ) assertResult(paragraph.length)(length.toInt) } - } From afb2bd732cf0372cf42d8ab2daf9e37011c09fd1 Mon Sep 17 00:00:00 2001 From: Pavlo Tsipinio Date: Tue, 22 Aug 2023 08:41:47 +0300 Subject: [PATCH 2/3] fixed build settings --- .gitignore | 3 ++- .travis.yml | 4 ++-- build.sbt | 2 +- project/build.properties | 2 +- project/plugins.sbt | 16 ++++++++++------ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 139d768..0128adc 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ test-output/ .vscode/ metals.sbt .metals -.bsp \ No newline at end of file +.bsp +.DS_Store \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ea7dd4a..c20f2f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ jdk: - openjdk8 scala: - - 2.11.12 - - 2.12.10 + - 2.12.18 + - 2.13.11 script: - sbt clean coverage test diff --git a/build.sbt b/build.sbt index ef6abf9..be9e406 100644 --- a/build.sbt +++ b/build.sbt @@ -54,7 +54,7 @@ pomExtra := -coverageMinimum := 70 +coverageMinimumStmtTotal := 70 coverageFailOnMinimum := true diff --git a/project/build.properties b/project/build.properties index 875b706..52413ab 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.2 +sbt.version=1.9.3 diff --git a/project/plugins.sbt b/project/plugins.sbt index 4a6db9c..ae10ef7 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,10 +4,10 @@ resolvers += Classpaths.sbtPluginReleases resolvers += Classpaths.typesafeReleases -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") -addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.2.7") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") +addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.3.11") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1") // Add the following to have Git manage your build versions resolvers += "jgit-repo" at "https://download.eclipse.org/jgit/maven" @@ -16,6 +16,10 @@ resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksam Resolver.ivyStylePatterns ) -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1") + +ThisBuild / libraryDependencySchemes ++= Seq( + "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always +) From a015e877b928de84937ccce0e5f0459e980aef21 Mon Sep 17 00:00:00 2001 From: Pavlo Tsipinio Date: Tue, 22 Aug 2023 11:07:55 +0300 Subject: [PATCH 3/3] added comment to plugins --- project/plugins.sbt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/plugins.sbt b/project/plugins.sbt index ae10ef7..b47f141 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,6 +4,8 @@ resolvers += Classpaths.sbtPluginReleases resolvers += Classpaths.typesafeReleases +// these plugins trigger 'java.lang.AssertionError: NoDenotation.owner while compiling ...' +// when compile java and scala sources addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.3.11")