Update to JUnit5 across all modules (#1668)
* Updated saga to JUnit 5 * Update fix for CI job in trampoline module * Updated update-method module to JUnit 5 * Upgraded to latest JUnit Jupiter JUnit 4 is not needed when using JUnit-Vintage * Reverted change to access modifier on Trampoline * Cleanup to resolve code smells * Formatting * Formatting * Migrating to JUnit5 and updating some Mockito patterns * Migrating to JUnit5 * Migrating to JUnit5 * Migrating to JUnit 5 * Formatting cleanup * Added missing scope for junit * Fixed tests that were not running previously. Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
@ -35,19 +35,9 @@
|
||||
|
||||
<artifactId>unit-of-work</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -23,17 +23,17 @@
|
||||
|
||||
package com.iluwatar.unitofwork;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* AppTest
|
||||
*/
|
||||
public class AppTest {
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
public void shouldExecuteWithoutException() {
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
}
|
||||
}
|
||||
|
@ -23,43 +23,32 @@
|
||||
|
||||
package com.iluwatar.unitofwork;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* tests {@link StudentRepository}
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class StudentRepositoryTest {
|
||||
|
||||
class StudentRepositoryTest {
|
||||
private final Student student1 = new Student(1, "Ram", "street 9, cupertino");
|
||||
private final Student student2 = new Student(1, "Sham", "Z bridge, pune");
|
||||
|
||||
private Map<String, List<Student>> context;
|
||||
@Mock
|
||||
private StudentDatabase studentDatabase;
|
||||
private StudentRepository studentRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = new HashMap<>();
|
||||
studentRepository = new StudentRepository(context, studentDatabase);
|
||||
}
|
||||
private final Map<String, List<Student>> context = new HashMap<>();
|
||||
private final StudentDatabase studentDatabase = mock(StudentDatabase.class);
|
||||
private final StudentRepository studentRepository = new StudentRepository(context, studentDatabase);;
|
||||
|
||||
@Test
|
||||
public void shouldSaveNewStudentWithoutWritingToDb() {
|
||||
void shouldSaveNewStudentWithoutWritingToDb() {
|
||||
studentRepository.registerNew(student1);
|
||||
studentRepository.registerNew(student2);
|
||||
|
||||
@ -68,7 +57,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDeletedStudentWithoutWritingToDb() {
|
||||
void shouldSaveDeletedStudentWithoutWritingToDb() {
|
||||
studentRepository.registerDeleted(student1);
|
||||
studentRepository.registerDeleted(student2);
|
||||
|
||||
@ -77,7 +66,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveModifiedStudentWithoutWritingToDb() {
|
||||
void shouldSaveModifiedStudentWithoutWritingToDb() {
|
||||
studentRepository.registerModified(student1);
|
||||
studentRepository.registerModified(student2);
|
||||
|
||||
@ -86,7 +75,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveAllLocalChangesToDb() {
|
||||
void shouldSaveAllLocalChangesToDb() {
|
||||
context.put(UnitActions.INSERT.getActionValue(), List.of(student1));
|
||||
context.put(UnitActions.MODIFY.getActionValue(), List.of(student1));
|
||||
context.put(UnitActions.DELETE.getActionValue(), List.of(student1));
|
||||
@ -99,7 +88,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotWriteToDbIfContextIsNull() {
|
||||
void shouldNotWriteToDbIfContextIsNull() {
|
||||
var studentRepository = new StudentRepository(null, studentDatabase);
|
||||
|
||||
studentRepository.commit();
|
||||
@ -108,16 +97,16 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotWriteToDbIfNothingToCommit() {
|
||||
void shouldNotWriteToDbIfNothingToCommit() {
|
||||
var studentRepository = new StudentRepository(new HashMap<>(), studentDatabase);
|
||||
|
||||
studentRepository.commit();
|
||||
|
||||
verifyZeroInteractions(studentDatabase);
|
||||
verifyNoMoreInteractions(studentDatabase);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() {
|
||||
void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() {
|
||||
context.put(UnitActions.MODIFY.getActionValue(), List.of(student1));
|
||||
context.put(UnitActions.DELETE.getActionValue(), List.of(student1));
|
||||
|
||||
@ -127,7 +116,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() {
|
||||
void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() {
|
||||
context.put(UnitActions.INSERT.getActionValue(), List.of(student1));
|
||||
context.put(UnitActions.DELETE.getActionValue(), List.of(student1));
|
||||
|
||||
@ -137,7 +126,7 @@ public class StudentRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() {
|
||||
void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() {
|
||||
context.put(UnitActions.INSERT.getActionValue(), List.of(student1));
|
||||
context.put(UnitActions.MODIFY.getActionValue(), List.of(student1));
|
||||
|
||||
@ -145,4 +134,4 @@ public class StudentRepositoryTest {
|
||||
|
||||
verify(studentDatabase, never()).delete(student1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user