I've noticed that some given setup logic in the @BeforeEach
method is also repeated in several individual test methods in the JpaTransactionManagerTests
.
Is there a specific reason for this duplication?
If not, is it okay if i remove duplicated setup in test methods?
for example
class JpaTransactionManagerTests {
// ...
@BeforeEach
void setup() {
given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);
}
@Test
void testTransactionCommit() {
given(manager.getTransaction()).willReturn(tx); // duplicated given setup
// ..
}
Comment From: rstoyanchev
Superseded by #34807.