Skip to content

Instantly share code, notes, and snippets.

@gokman
Created February 2, 2017 06:26
Show Gist options
  • Select an option

  • Save gokman/0a8887fabb9778d4b26888ca00ffe6e5 to your computer and use it in GitHub Desktop.

Select an option

Save gokman/0a8887fabb9778d4b26888ca00ffe6e5 to your computer and use it in GitHub Desktop.
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class UserRepositoryTests {
@Autowired
private TestEntityManager entityManager;
@Autowired
private UserRepository repository;
@Autowired
SystemUtils systemUtils;
AcilUser user;
@Before
public void init(){
user = new User();
user.setId(111);
user.setName("name");
user.setSurname("surname");
this.entityManager.persist(user);
}
@Test
public void findByIdShouldReturnUser() throws Exception {
Optional<User> user = this.repository.findOneById(111);
Assert.assertEquals(user.get().getId(), 111);
}
@Test
@Modifying(clearAutomatically = true)
public void updateUserStateShouldReturnNewState() throws Exception {
this.repository.updateUserState(111, UserStatus.ACTIVE.getValue());
entityManager.refresh(user);
Optional<User> user = this.repository.findOneById(111);
Assert.assertEquals(user.get().getState(), UserStatus.ACTIVE.getValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment