Last active
April 30, 2019 20:15
-
-
Save mitchtabian/cb5ab9933b9a5033a42dcd5fb7ed5e65 to your computer and use it in GitHub Desktop.
Repeated Test with RepetitionInfo. Reference: https://gist.github.com/mitchtabian/f66938b82ef711be321778e5634d18e2
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
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.DisplayName; | |
import org.junit.jupiter.api.RepeatedTest; | |
import org.junit.jupiter.api.RepetitionInfo; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.function.Executable; | |
import static org.junit.jupiter.api.Assertions.*; | |
@DisplayName("Api Service Test") | |
public class ApiServiceNotifierTest { | |
private MockApiServiceDouble apiServiceDouble; | |
@BeforeEach | |
void init(){ | |
apiServiceDouble = new MockApiServiceDouble(); | |
} | |
@Test | |
@DisplayName("Insert a new user using ApiServiceManager") | |
void testInsertNewUser(){ | |
ApiServiceManager notifier = new ApiServiceManager(apiServiceDouble); | |
User user = new User("Mitch", "Mitch@tabian.ca", 29); | |
notifier.insertNewUser(user); | |
assertEquals(1, apiServiceDouble.createdUsers.size()); | |
final User expectedUser = apiServiceDouble.createdUsers.get(0); | |
assertAll( | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals("Mitch", expectedUser.getName()); | |
} | |
}, | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals("Mitch@tabian.ca", expectedUser.getEmail()); | |
} | |
}, | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals(29, expectedUser.getAge()); | |
} | |
} | |
); | |
} | |
@RepeatedTest(value = 3, name = "-{displayName} -> {currentRepetition}/{totalRepetitions}") | |
void testRepeatInsertUser(RepetitionInfo repetitionInfo){ | |
ApiServiceManager notifier = new ApiServiceManager(apiServiceDouble); | |
User user = new User("Mitch", "Mitch@tabian.ca", -1); | |
final long someNumber = repetitionInfo.getCurrentRepetition() + 10; | |
user.setAge((int)someNumber); | |
notifier.insertNewUser(user); | |
assertEquals(1, apiServiceDouble.createdUsers.size()); | |
final User expectedUser = apiServiceDouble.createdUsers.get(0); | |
assertAll( | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals("Mitch", expectedUser.getName()); | |
} | |
}, | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals("Mitch@tabian.ca", expectedUser.getEmail()); | |
} | |
}, | |
new Executable() { | |
@Override | |
public void execute() throws Throwable { | |
assertEquals(someNumber, expectedUser.getAge()); | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment