package com.goree.api.controller;

import java.util.Date;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.goree.api.Application;
import com.goree.api.domain.Member;
import com.goree.api.domain.Member.Gender;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={Application.class})
public class MemberTest {

    @Autowired
    private MemberController controller;
    
    @Test
    public void findMemberAll() {
        List<Member> members = controller.findMemberAll();
        Assert.assertNotNull(members);
        Assert.assertFalse(members.isEmpty());
    }
    
    @Test
    public void registerMember() {
        Member expected = new Member();
        expected.setEmail("rpxhdnjsdud"+new Date().getTime()+"@nate.com");
        expected.setPassword("qlalfqjsgh");
        expected.setFullName("Wonyoung Ju");
        expected.setAge(22);
        expected.setGender(Gender.M);
        expected.setPhone("010-8826-0173");
        
        Member registered = controller.registerMember(expected);
        Assert.assertNotNull(registered);
        Assert.assertEquals(expected.getEmail(), registered.getEmail());
    }
    
    @Test
    public void deleteMemberById() {
        List<Member> members = controller.findMemberAll();
        Member toBeDeleted = members.get(members.size()-1);
        controller.deleteMemberById(toBeDeleted.getId());
        
        boolean deleted = !controller.findMemberAll().stream()
                .anyMatch(m-> m.getId() == toBeDeleted.getId());
        Assert.assertTrue(deleted);
    }
}

@@ -100,16 +100,41 @@
 Assert;%0A
+import org.junit.Before;%0A
 import o
@@ -148,16 +148,16 @@
 t.Test;%0A
-
 import o
@@ -384,16 +384,81 @@
 sRunner;
+%0Aimport org.springframework.transaction.annotation.Transactional;
 %0A%0Aimport
@@ -666,16 +666,31 @@
 class%7D)%0A
+@Transactional%0A
 public c
@@ -763,16 +763,424 @@
 troller;
+%0A%0A    private Member testMember;%0A    %0A    @Before%0A    public void setUp() %7B%0A        Member member = new Member();%0A        member.setEmail(%22test@gmail.com%22);%0A        member.setPassword(%22qlalfqjsgh%22);%0A        member.setFullName(%22Wonyoung Ju%22);%0A        member.setAge(22);%0A        member.setGender(Gender.M);%0A        member.setPhone(%22010-8826-0173%22);%0A        testMember = controller.registerMember(member);%0A    %7D
 %0A    %0A  
@@ -1378,32 +1378,33 @@
 %7D%0A    %0A    @Test
+ 
 %0A    public void
@@ -1989,127 +1989,8 @@
 ) %7B%0A
-        List%3CMember%3E members = controller.findMemberAll();%0A        Member toBeDeleted = members.get(members.size()-1);%0A
     
@@ -2022,26 +2022,25 @@
 erById(t
-oBeDeleted
+estMember
 .getId()
@@ -2162,18 +2162,17 @@
 == t
-oBeDeleted
+estMember
 .get

refactor member test