package io.crowdcode.flaschenlager.user.repository;

import io.crowdcode.flaschenlager.user.model.User;
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.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

@RunWith(SpringRunner.class)
@DataJpaTest
public class UserRepositoryTest {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private TestEntityManager entityManager;

    @Test
    public void testCreateUser() throws Exception {
        User user = buildDefaultUser();

        userRepository.save(user);

        assertThat(user.getId(), is(notNullValue()));
    }

    @Test
    public void testFindByEmail() throws Exception {
        User user = entityManager.persist(buildDefaultUser());

        assertThat(userRepository.findByEmail("junit@crowdcode.io").getId(), is(user.getId()));
    }

    private User buildDefaultUser() {
        return new User()
                .setName("Name")
                .setPassword("secret")
                .setEmail("junit@crowdcode.io");
    }
}
@@ -46,16 +46,76 @@
 itory;%0A%0A
+import io.crowdcode.flaschenlager.user.fixture.UserFixture;%0A
 import i
@@ -911,16 +911,28 @@
  user = 
+UserFixture.
 buildDef
@@ -943,16 +943,16 @@
 User();%0A
-
 %0A       
@@ -1146,16 +1146,28 @@
 persist(
+UserFixture.
 buildDef
@@ -1287,196 +1287,5 @@
  %7D%0A%0A
-    private User buildDefaultUser() %7B%0A        return new User()%0A                .setName(%22Name%22)%0A                .setPassword(%22secret%22)%0A                .setEmail(%22junit@crowdcode.io%22);%0A    %7D%0A
 %7D

use user fixture