Added simple integration test.

This commit is contained in:
Alexey Zinchenko 2019-05-18 00:16:18 +03:00
parent a0df8027e6
commit 463113b161
3 changed files with 45 additions and 17 deletions

View File

@ -77,6 +77,12 @@
<artifactId>mapstruct-jdk8</artifactId>
<version>1.3.0.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<version>1.4.199</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>

View File

@ -1,17 +0,0 @@
package com.github.prominence.carrepair;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CarRepairApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -0,0 +1,39 @@
package com.github.prominence.carrepair;
import com.github.prominence.carrepair.model.domain.Client;
import com.github.prominence.carrepair.repository.ClientRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@DataJpaTest
public class ClientRepositoryIntegrationTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private ClientRepository clientRepository;
@Test
public void whenFindById_thenReturnClient() {
// given
Client client = new Client("firstName", "middleName", "lastName", "123456789");
entityManager.persist(client);
entityManager.flush();
// when
Client found = clientRepository.findById(client.getId()).get();
// then
assertThat(found.hashCode()).isEqualTo(client.hashCode());
}
}