This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
package space.kklochko.spring_rest_example.models.factories
|
||||
|
||||
import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
|
||||
class TokenFactorySpec extends Specification {
|
||||
def "Create a token for a user"() {
|
||||
given: "I have a string token factory"
|
||||
def stringTokenFactory = Mock(StringTokenFactory)
|
||||
stringTokenFactory.create(_) >> "token"
|
||||
|
||||
and: "I have a token factory"
|
||||
@Subject
|
||||
def factory = new TokenFactory(stringTokenFactory)
|
||||
|
||||
and: "I have a username and a role"
|
||||
String username = "user"
|
||||
String role = "USER"
|
||||
|
||||
when: "I create a token"
|
||||
def token = factory.create(username, role)
|
||||
|
||||
then: "The token is the same if the same input data."
|
||||
with(token) {
|
||||
getUsername() == username
|
||||
getRole() == role
|
||||
getToken() == "token"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user