Skip to content

Instantly share code, notes, and snippets.

@mitchtabian
Last active April 30, 2019 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchtabian/cb5ab9933b9a5033a42dcd5fb7ed5e65 to your computer and use it in GitHub Desktop.
Save mitchtabian/cb5ab9933b9a5033a42dcd5fb7ed5e65 to your computer and use it in GitHub Desktop.
Repeated Test with RepetitionInfo. Reference: https://gist.github.com/mitchtabian/f66938b82ef711be321778e5634d18e2
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