Skip to content

Instantly share code, notes, and snippets.

View mario-rezende-ifood's full-sized avatar

Mario Rezende mario-rezende-ifood

  • iFood
  • Sao Paulo / Brazil
View GitHub Profile
@Test
void validateUserRegistration() {
// setup
String name = "Fulano"
int age = 20
String email = "[email protected]"
// execute
User user = UserService().register(name, age, email)
def 'Validate user registration'() {
given: 'user data'
def name = "Fulano"
def age = 20
def email = "[email protected]"
when: 'register the user'
def user = UserService().register(name, age, email)
def 'Allow user access only for 18 over'(name, age, expected) {
given: 'user entity'
def user = new User(name, age)
when: 'validate user access'
def userCanAccess = AccessService().grantUser(user)
then:
userCanAccess == expected
then:
name == 'Fulano'
name != 'Beltrano'
age >= 20
age < 100
given: 'open a database connection'
// code goes here
and: 'seed the customer table'
// code goes here
and: 'seed the product table'
// code goes here
def 'Maximum of two numbers'() {
expect:
Math.max(a, b) == c
where:
a | b | c
1 | 3 | 3
7 | 4 | 4
0 | 0 | 0
Condition not satisfied:
Math.max(a, b) == c
| | | | | |
| 7 7 4 | 4
| false
class java.lang.Math
@Unroll
def 'Maximum of #a and #b is #c'() {
expect:
Math.max(a, b) == c
where:
a | b | c
1 | 3 | 3
7 | 4 | 4
maximum of 1 and 3 is 3 PASSED
maximum of 7 and 4 is 4 FAILED
Math.max(a, b) == c
| | | | | |
| 7 7 4 | 4
| false
class java.lang.Math
maximum of 0 and 0 is 0 PASSED
class Publisher {
List<Subscriber> subscribers = []
void send(String message){
subscribers*.receive(message)
}
}
interface Subscriber {
void receive(String message)
}