Skip to content

Commit

Permalink
Merge branch 'release/v1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonkmi committed Nov 24, 2019
2 parents f58b924 + 0429a74 commit 4823d36
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [v1.0.7]

### Added
- Parsed args validation method. If an argument is missing its value, it throws an exception.
- Added unit test when args list is empty

## [v1.0.6]

### Changed
Expand Down Expand Up @@ -37,4 +43,5 @@ All notable changes to this project will be documented in this file.
[v1.0.3]: https://github.com/andersonkmi/spark-utils/compare/v1.0.2...v1.0.3
[v1.0.4]: https://github.com/andersonkmi/spark-utils/compare/v1.0.3...v1.0.4
[v1.0.5]: https://github.com/andersonkmi/spark-utils/compare/v1.0.4...v1.0.5
[v1.0.6]: https://github.com/andersonkmi/spark-utils/compare/v1.0.5...v1.0.6
[v1.0.6]: https://github.com/andersonkmi/spark-utils/compare/v1.0.5...v1.0.6
[v1.0.7]: https://github.com/andersonkmi/spark-utils/compare/v1.0.6...v1.0.7
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ organization := "org.codecraftlabs.spark"

name := "spark-utils"

val appVersion = "1.0.6"
val appVersion = "1.0.7"

val appName = "spark-utils"

Expand Down
7 changes: 7 additions & 0 deletions src/main/scala/org/codecraftlabs/spark/utils/ArgsUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.collection.mutable
object ArgsUtils {
private val ArgsKeyIndicator: String = "--"

@throws(classOf[Exceptions])
def parseArgs(args: Array[String]): Map[String, String] = {
val result = mutable.Map[String, String]()

Expand All @@ -21,7 +22,13 @@ object ArgsUtils {
result(currentKey) = currentItem
}
}
validateParsedArgs(result.toMap)
result.toMap
}
}

@throws(classOf[Exceptions])
private def validateParsedArgs(args: Map[String, String]): Unit = {
if(args.exists(_._2.isEmpty)) throw Exceptions("Missing arguments")
}
}
3 changes: 3 additions & 0 deletions src/main/scala/org/codecraftlabs/spark/utils/Exceptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.codecraftlabs.spark.utils

final case class Exceptions(private val message: String = "", private val cause: Throwable = None.orNull) extends Exception(message, cause)
13 changes: 8 additions & 5 deletions src/test/scala/org/codecraftlabs/spark/utils/ArgsUtilSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ class ArgsUtilSpec extends FlatSpec with Matchers with BeforeAndAfterAll {
result.size shouldEqual 0
}

"Single args" should "return 1 empty arg" in {
val args = Array("--test")
"Empty args" should "be empty" in {
val args = Array.empty[String]
val result = ArgsUtils.parseArgs(args)
result should not be null
result.size shouldEqual 1
result.head._1 shouldEqual "--test"
result.head._2 shouldEqual ""
result.size shouldEqual 0
}

"Single args" should "return 1 empty arg" in {
val args = Array("--test")
an [Exceptions] should be thrownBy ArgsUtils.parseArgs(args)
}

"Single arguments" should "return 1 valid arg" in {
Expand Down

0 comments on commit 4823d36

Please sign in to comment.