forked from pepegar/hammock
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pepegar#111 Added methods to Status (pepegar#112)
* pepegar#111 added methods to Status * pepegar#111 added tests
- Loading branch information
Showing
2 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package hammock | ||
|
||
import org.scalatest.{Matchers, WordSpec} | ||
|
||
class StatusSpec extends WordSpec with Matchers { | ||
val status: Int => Status = (code: Int) => Status(code, "", "") | ||
|
||
"Status.isInformational" when { | ||
"status code is 1xx" should { | ||
"return true" in { | ||
(100 to 102).foreach(code => assert(status(code).isInformational)) | ||
} | ||
} | ||
|
||
"status code is not 1xx" should { | ||
"return false" in { | ||
assert(!status(200).isInformational) | ||
assert(!status(300).isInformational) | ||
assert(!status(400).isInformational) | ||
assert(!status(500).isInformational) | ||
} | ||
} | ||
} | ||
|
||
"Status.isSuccess" when { | ||
"status code is 2xx" should { | ||
"return true" in { | ||
(200 to 208).foreach(code => assert(status(code).isSuccess)) | ||
} | ||
} | ||
|
||
"status code is not 2xx" should { | ||
"return false" in { | ||
assert(!status(100).isSuccess) | ||
assert(!status(300).isSuccess) | ||
assert(!status(400).isSuccess) | ||
assert(!status(500).isSuccess) | ||
} | ||
} | ||
} | ||
|
||
"Status.isRedirection" when { | ||
"status code is 3xx" should { | ||
"return true" in { | ||
(300 to 308).foreach(code => assert(status(code).isRedirection)) | ||
} | ||
} | ||
|
||
"status code is not 3xx" should { | ||
"return false" in { | ||
assert(!status(100).isRedirection) | ||
assert(!status(200).isRedirection) | ||
assert(!status(400).isRedirection) | ||
assert(!status(500).isRedirection) | ||
} | ||
} | ||
} | ||
|
||
"Status.isClientError" when { | ||
"status code is 4xx" should { | ||
"return true" in { | ||
(400 to 451).foreach(code => assert(status(code).isClientError)) | ||
} | ||
} | ||
|
||
"status code is not 4xx" should { | ||
"return false" in { | ||
assert(!status(100).isClientError) | ||
assert(!status(200).isClientError) | ||
assert(!status(300).isClientError) | ||
assert(!status(500).isClientError) | ||
} | ||
} | ||
} | ||
|
||
"Status.isServerError" when { | ||
"status code is 5xx" should { | ||
"return true" in { | ||
(500 to 599).foreach(code => assert(status(code).isServerError)) | ||
} | ||
} | ||
|
||
"status code is not 5xx" should { | ||
"return false" in { | ||
assert(!status(100).isServerError) | ||
assert(!status(200).isServerError) | ||
assert(!status(300).isServerError) | ||
assert(!status(400).isServerError) | ||
} | ||
} | ||
} | ||
} |