[Notice] Announcing the End of Demo Server [Read me]
Keesun Baik 2014-08-04
Test: enhanced tests' performance for tests in models package
@94f0d9f733fbdada675538a0bf8f23e19d3c7bbb
app/models/PullRequest.java
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
@@ -934,10 +934,4 @@
         return this.isConflict == false &&
                 this.mergedCommitIdFrom != null && this.mergedCommitIdTo != null;
     }
-
-    @Override
-    public Object clone() throws CloneNotSupportedException {
-        PullRequest cloned = (PullRequest)super.clone();
-        return cloned;
-    }
 }
app/models/Role.java
--- app/models/Role.java
+++ app/models/Role.java
@@ -34,7 +34,7 @@
 @Entity
 public class Role extends Model {
     private static final long serialVersionUID = 1L;
-    private static Finder<Long, Role> find = new Finder<>(Long.class,
+    public static Finder<Long, Role> find = new Finder<>(Long.class,
             Role.class);
 
     @Id
conf/test-data.yml
--- conf/test-data.yml
+++ conf/test-data.yml
@@ -24,7 +24,6 @@
         state:          ACTIVE
         email:          doortts@gmail.com
         createdDate:           2012-07-01 08:00:00
-        state: ACTIVE
     - !!models.User
         name:           eungjun
         loginId:        nori
test/controllers/PullRequestAppTest.java
--- test/controllers/PullRequestAppTest.java
+++ test/controllers/PullRequestAppTest.java
@@ -174,16 +174,26 @@
 
     @Test
     public void testOpenPullRequestBadRequest() throws Exception {
+        //Given
         initParameters("yobi", "projectYobi", 1L);
         User currentUser = User.findByLoginId("admin");
 
+        User projectOwner = User.findByLoginId("yobi");
+
+        final String uri = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber;
+        callAction(
+                controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber),
+                fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, projectOwner.id.toString())
+        );
+
+        //When
         Result result = callAction(
                 controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber),
-                fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber)
-                .withSession(UserApp.SESSION_USERID, currentUser.id.toString())
+                fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, currentUser.id.toString())
               );
 
-        assertThat(status(result)).isEqualTo(BAD_REQUEST);
+        //Then
+        assertThat(status(result)).isEqualTo(BAD_REQUEST).describedAs("open already opened");
     }
 
     @Test
@@ -230,8 +240,8 @@
         Result result = callAction(
                 controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null),
                 fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork")
-                .withSession(UserApp.SESSION_USERID, currentUser.id.toString())
-              );
+                        .withSession(UserApp.SESSION_USERID, currentUser.id.toString())
+        );
 
         assertThat(status(result)).isEqualTo(OK);
     }
@@ -244,8 +254,8 @@
         Result result = callAction(
                 controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null),
                 fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork")
-                .withSession(UserApp.SESSION_USERID, currentUser.id.toString())
-              );
+                        .withSession(UserApp.SESSION_USERID, currentUser.id.toString())
+        );
 
         assertThat(status(result)).isEqualTo(OK);
 
test/models/CommentThreadTest.java
--- test/models/CommentThreadTest.java
+++ test/models/CommentThreadTest.java
@@ -21,6 +21,7 @@
 package models;
 
 import org.apache.shiro.util.ThreadState;
+import org.junit.After;
 import org.junit.Test;
 import org.junit.Before;
 import utils.JodaDateUtil;
@@ -45,6 +46,8 @@
     private User anonymous;
     private Project project;
     private SimpleCommentThread thread;
+    private List<Long> threadIds;
+    String commitId = "123123";
 
     @Before
     public void before() {
@@ -68,14 +71,20 @@
         assertThat(ProjectUser.isMember(member.id, project.id)).describedAs("member is a member").isTrue();
         assertThat(ProjectUser.isMember(author.id, project.id)).describedAs("author is not a member").isFalse();
         assertThat(project.projectScope).isEqualTo(ProjectScope.PUBLIC);
+
+        threadIds = addTestData(commitId);
+    }
+
+    @After
+    public void after() {
+        thread.delete();
+        for(Long id : threadIds) {
+            CommentThread.find.byId(id).delete();
+        }
     }
 
     @Test
     public void findByCommitId() {
-        // given
-        String commitId = "123123";
-        addTestData(commitId);
-
         // when
         List<CommentThread> threadList = CommentThread.findByCommitId(commitId);
 
@@ -87,10 +96,6 @@
 
     @Test
     public void findByCommitIdAndState() {
-        // given
-        String commitId = "123123";
-        List<Long> threadIds = addTestData(commitId);
-
         // when and then
         List<CommentThread> threadList = CommentThread.findByCommitIdAndState(commitId, CommentThread.ThreadState.OPEN);
         assertThat(threadList.get(0).id).isEqualTo(threadIds.get(0));
test/models/IssueTest.java
--- test/models/IssueTest.java
+++ test/models/IssueTest.java
@@ -31,6 +31,7 @@
 import models.enumeration.State;
 
 import org.apache.commons.lang3.time.DateUtils;
+import org.junit.After;
 import org.junit.Test;
 import org.junit.Before;
 
@@ -64,6 +65,16 @@
         issue.save();
     }
 
+    @After
+    public void after() {
+        issue.setProject(project);
+        issue.setTitle("hello");
+        issue.setBody("world");
+        issue.setAuthor(author);
+        issue.state = State.OPEN;
+        issue.update();
+    }
+
     @Test
     public void vote() {
         // when
test/models/MilestoneTest.java
--- test/models/MilestoneTest.java
+++ test/models/MilestoneTest.java
@@ -20,14 +20,21 @@
  */
 package models;
 
+import com.avaje.ebean.Ebean;
 import models.enumeration.State;
 
 import org.apache.commons.lang3.time.DateUtils;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import play.i18n.Messages;
+import play.libs.Yaml;
+import support.Helpers;
 import utils.JodaDateUtil;
+import utils.YamlUtil;
 
+import java.io.IOException;
 import java.util.*;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -40,7 +47,7 @@
         Milestone newMilestone = new Milestone();
         newMilestone.dueDate = new Date();
         newMilestone.setContents("테스트 마일스톤");
-        newMilestone.project = Project.find.byId(1l);
+        newMilestone.project = Project.find.byId(3l);
         newMilestone.title = "0.1";
 
         // When
@@ -48,6 +55,8 @@
 
         // Then
         assertThat(newMilestone.id).isNotNull();
+        //To keep data clean after this test.
+        newMilestone.delete();
     }
 
     @Test
@@ -82,15 +91,21 @@
     @Test
     public void delete() throws Exception {
         // Given
-        Milestone firstMilestone = Milestone.findById(1l);
-        assertThat(firstMilestone).isNotNull();
+        Milestone milestone = new Milestone();
+        milestone.title = "test";
+        milestone.project = getTestProject();
+        milestone.contents = "test";
+        milestone.save();
+
+        Milestone savedMilestone = Milestone.findById(milestone.id);
+        assertThat(savedMilestone).isNotNull();
 
         // When
-        firstMilestone.delete();
+        savedMilestone.delete();
 
         //Then
-        firstMilestone = Milestone.findById(1l);
-        assertThat(firstMilestone).isNull();
+        savedMilestone = Milestone.findById(milestone.id);
+        assertThat(savedMilestone).isNull();
     }
 
     @Test
@@ -221,6 +236,8 @@
         m5 = Milestone.findById(5l);
         assertThat(m5.getNumTotalIssues()).isEqualTo(totalNumber + 1);
         assertThat(m5.getNumOpenIssues()).isEqualTo(openNumber + 1);
+        //To keep data clean after this test.
+        issue.delete();
     }
 
     @Test
test/models/ModelTest.java
--- test/models/ModelTest.java
+++ test/models/ModelTest.java
@@ -20,14 +20,10 @@
  */
 package models;
 
-import org.junit.After;
 import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import play.test.FakeApplication;
 import play.test.Helpers;
-//import support.EbeanUtil;
-
 
 public class ModelTest<T> {
     protected static FakeApplication app;
@@ -37,17 +33,16 @@
     public ModelTest() {
     }
 
-    @Before
-    public  void startApp() {
+    @BeforeClass
+    public static void startApp() {
         app = support.Helpers.makeTestApplication();
         Helpers.start(app);
     }
 
-    @After
-    public void stopApp() {
+    @AfterClass
+    public static void stopApp() {
         Helpers.stop(app);
     }
-
     /**
      * Returns the first user. (id : 2 / name : yobi)
      *
test/models/OrganizationTest.java
--- test/models/OrganizationTest.java
+++ test/models/OrganizationTest.java
@@ -20,9 +20,11 @@
  */
 package models;
 
+import org.junit.Before;
 import org.junit.Test;
 import play.data.validation.Validation;
 
+import java.io.IOException;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
test/models/OrganizationUserTest.java
--- test/models/OrganizationUserTest.java
+++ test/models/OrganizationUserTest.java
@@ -23,6 +23,7 @@
 
 import controllers.routes;
 import models.enumeration.RoleType;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -37,34 +38,30 @@
 /**
  * Created by kcs on 2/21/14.
  */
-public class OrganizationUserTest {
-    protected static FakeApplication app;
+public class OrganizationUserTest extends ModelTest<OrganizationUser> {
 
-    @BeforeClass
-    public static void beforeClass() {
-        callAction(
-                routes.ref.Application.init()
-        );
-    }
+    Organization organization;
 
     @Before
     public void before() {
-        app = support.Helpers.makeTestApplication();
-        Helpers.start(app);
+        organization = createOrganization();
     }
 
-    private Organization createOrganization(String name) {
-        Organization organization = new Organization();
-        organization.name = name;
-        organization.save();
+    @After
+    public void after() {
+        organization.delete();
+    }
 
+    private Organization createOrganization() {
+        Organization organization = new Organization();
+        organization.name = "TestOrganization";
+        organization.save();
         return organization;
     }
 
     @Test
     public void addMember() {
         // Given
-        Organization organization = createOrganization("TestOrganization");
         User user = User.findByLoginId("laziel");
 
         // When
@@ -78,7 +75,6 @@
     @Test
     public void checkMemberInfo() {
         // Given
-        Organization organization = createOrganization("TestOrganization");
         User user = User.findByLoginId("laziel");
         Long roleType = RoleType.ORG_ADMIN.roleType();
 
@@ -96,7 +92,6 @@
     @Test
     public void deleteMember() {
         // Given
-        Organization organization = createOrganization("TestOrganization");
         User user = User.findByLoginId("laziel");
         Long roleType = RoleType.ORG_ADMIN.roleType();
 
@@ -112,7 +107,6 @@
     @Test
     public void editMember() {
         // Given
-        Organization organization = createOrganization("TestOrganization");
         User user = User.findByLoginId("laziel");
         Long firstRoleType = RoleType.ORG_ADMIN.roleType();
         Long secondRoleType = RoleType.ORG_MEMBER.roleType();
@@ -130,7 +124,6 @@
     @Test
     public void listOrganization() {
         // Given
-        Organization organization = createOrganization("TestOrganization");
         User laziel = User.findByLoginId("laziel");
         User doortts = User.findByLoginId("doortts");
 
test/models/PostingTest.java
--- test/models/PostingTest.java
+++ test/models/PostingTest.java
@@ -69,12 +69,7 @@
     @Test
     public void save() throws Exception {
         // Given
-        Posting post = new Posting();
-        post.setBody("new Contents");
-        post.title = "new_title";
-        post.createdDate = JodaDateUtil.now();
-        post.project = Project.find.byId(1l);
-        post.setAuthor(getTestUser());
+        Posting post = getNewPosting();
 
         // When
         post.save();
@@ -87,16 +82,35 @@
         assertThat(actual.createdDate).isEqualTo(post.createdDate);
         assertThat(actual.authorId).isEqualTo(getTestUser().id);
         assertThat(actual.id).isEqualTo(post.id);
+
+        // To keep data clean after this test.
+        post.delete();
+    }
+
+    private Posting getNewPosting() {
+        Posting post = new Posting();
+        post.setBody("new Contents");
+        post.title = "new_title";
+        post.createdDate = JodaDateUtil.now();
+        post.project = Project.find.byId(1l);
+        post.setAuthor(getTestUser());
+        return post;
     }
 
     @Test
     public void delete() throws Exception {
         // Given
+        Posting post = getNewPosting();
+        post.save();
+        long postId = post.id;
+        assertThat(Posting.finder.byId(postId)).isNotNull();
+
         // When
-        Posting.finder.byId(1l).delete();
+        Posting.finder.byId(postId).delete();
+
         // Then
-        assertThat(Posting.finder.byId(1l)).isNull();
-        assertThat(PostingComment.find.byId(1l)).isNull();
+        assertThat(Posting.finder.byId(postId)).isNull();
+        assertThat(PostingComment.find.byId(postId)).isNull();
     }
 
     @Test
test/models/ProjectTest.java
--- test/models/ProjectTest.java
+++ test/models/ProjectTest.java
@@ -34,11 +34,7 @@
     @Test
     public void create() throws Exception {
         // Given
-        Project project = new Project();
-        project.name = "prj_test";
-        project.overview = "Overview for prj_test";
-        project.projectScope = ProjectScope.PRIVATE;
-        project.vcs = "GIT";
+        Project project = getNewProject();
         // When
         Project.create(project);
         // Then
@@ -47,6 +43,15 @@
         assertThat(actualProject).isNotNull();
         assertThat(actualProject.name).isEqualTo("prj_test");
         assertThat(actualProject.siteurl).isEqualTo("http://localhost:9000/prj_test");
+    }
+
+    private Project getNewProject() {
+        Project project = new Project();
+        project.name = "prj_test";
+        project.overview = "Overview for prj_test";
+        project.projectScope = ProjectScope.PRIVATE;
+        project.vcs = "GIT";
+        return project;
     }
 
     @Test
@@ -70,14 +75,17 @@
     @Test
     public void delete() throws Exception {
         // Given
+        Project project = getNewProject();
+        Project.create(project);
+        long projectId = project.id;
         // When
-        Project.find.byId(1l).delete();
+        Project.find.byId(projectId).delete();
 
         // Then
-        assertThat(Project.find.byId(1l)).isNull();
-        assertThat(ProjectUser.findByIds(1l, 1l)).isNull();
-        assertThat(Issue.finder.byId(1l)).isNull();
-        assertThat(Milestone.findById(1l)).isNull();
+        assertThat(Project.find.byId(projectId)).isNull();
+        assertThat(ProjectUser.findMemberListByProject(projectId)).isEmpty();
+        assertThat(Issue.finder.where().eq("project.id", projectId).findList()).isEmpty();
+        assertThat(Milestone.findByProjectId(projectId)).isEmpty();
     }
 
     @Test
test/models/ProjectUserTest.java
--- test/models/ProjectUserTest.java
+++ test/models/ProjectUserTest.java
@@ -43,6 +43,8 @@
         // Then
         assertThat(ProjectUser.findByIds(2l, 3l).role.id)
                 .isEqualTo(2l);
+        // To keep data clean after this test.
+        ProjectUser.delete(2l, 3l);
     }
 
     @Test
@@ -55,6 +57,9 @@
         // Then
         assertThat(ProjectUser.findByIds(2l, 1l).role.id).isEqualTo(2l);
         assertThat(ProjectUser.findByIds(2l, 3l).role.id).isEqualTo(2l);
+        // To keep data clean after this test.
+        ProjectUser.assignRole(2l, 1l, 1l);
+        ProjectUser.delete(2l, 3l);
     }
 
     @Test
@@ -70,6 +75,8 @@
         // Then
         assertThat(ProjectUser.checkOneMangerPerOneProject(userIdCase1, 3l)).isEqualTo(true);
         assertThat(ProjectUser.checkOneMangerPerOneProject(userIdCase2, 3l)).isEqualTo(false);
+        // To keep data clean after this test.
+        ProjectUser.delete(2l, 3l);
     }
 
     @Test
test/models/PullRequestTest.java
--- test/models/PullRequestTest.java
+++ test/models/PullRequestTest.java
@@ -43,10 +43,86 @@
 import java.util.regex.Pattern;
 
 import static org.fest.assertions.Assertions.assertThat;
-import static play.test.Helpers.callAction;
 import static utils.FileUtil.rm_rf;
 
 public class PullRequestTest extends ModelTest<PullRequest> {
+    private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/";
+    private static final String REPO_PREFIX = "resources/test/repo/git/";
+    private static final String LOCAL_REPO_PREFIX = "resources/test/local-repo/git/";
+
+    private RevCommit baseCommit;
+    private RevCommit firstCommit;
+    private RevCommit secondCommit;
+    private PullRequest pullRequest;
+    private Project forkedProject;
+
+    @Before
+    public void initRepositories() throws IOException, GitAPIException, ServletException,
+            ClientException {
+        GitRepository.setRepoPrefix(REPO_PREFIX);
+        GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX);
+
+        app = support.Helpers.makeTestApplication();
+        Helpers.start(app);
+
+        Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
+        forkedProject = Project.findByOwnerAndProjectName("yobi", "projectYobi-1");
+
+        // 1. projectYobi 저장소를 만듦
+        RepositoryService.createRepository(project);
+
+        // 2. projectYobi 저장소에 커밋 하나
+        {
+            String localRepoPath = LOCAL_REPO_PREFIX + project.name;
+            Git git = Git.cloneRepository()
+                    .setURI(GitRepository.getGitDirectoryURL(project))
+                    .setDirectory(new File(localRepoPath))
+                    .call();
+            Repository repo = git.getRepository();
+            baseCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), "test.txt",
+                    "apple\nbanana\ncat\n", "commit 1");
+            git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call();
+        }
+
+        // 3. 포크된 프로젝트 클론된 저장소 만들기
+        GitRepository.cloneLocalRepository(project, forkedProject);
+
+        // 4. 포크된 저장소에 새 브랜치를 만들어 그 브랜치에 커밋을 두개 하고
+        {
+            String localRepoPath = LOCAL_REPO_PREFIX + forkedProject.name;
+            Git git = Git.cloneRepository()
+                    .setURI(GitRepository.getGitDirectoryURL(forkedProject))
+                    .setDirectory(new File(localRepoPath))
+                    .call();
+            git.branchCreate().setName("fix/1").call();
+            git.checkout().setName("fix/1").call();
+            Repository repo = git.getRepository();
+            assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse();
+            firstCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(),
+                    "test.txt", "apple\nbanana\ncorn\n", "commit 1");
+            secondCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(),
+                    "test.txt", "apple\nbanana\ncake\n", "commit 2");
+            git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call();
+        }
+
+        // 5. 그 브랜치로 projectYobi에 pullrequest를 보낸다.
+        pullRequest = PullRequest.createNewPullRequest(forkedProject, project, "refs/heads/fix/1",
+                "refs/heads/master");
+
+        // 6. attempt merge
+        boolean isConflict = pullRequest.attemptMerge().conflicts();
+
+        assertThat(isConflict).isFalse();
+    }
+
+    @After
+    public void after() {
+        rm_rf(new File(REPO_PREFIX));
+        rm_rf(new File(MERGING_REPO_PREFIX));
+        rm_rf(new File(LOCAL_REPO_PREFIX));
+        Helpers.stop(app);
+    }
+
     @Test
     public void addIssueEvent() {
         // Given
@@ -184,83 +260,6 @@
         PullRequestEvent event = new PullRequestEvent();
         event.created = DateUtils.parseDate(str, "yyyy-MM-dd");
         return event;
-    }
-
-    private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/";
-    private static final String REPO_PREFIX = "resources/test/repo/git/";
-    private static final String LOCAL_REPO_PREFIX = "resources/test/local-repo/git/";
-
-    private RevCommit baseCommit;
-    private RevCommit firstCommit;
-    private RevCommit secondCommit;
-    private PullRequest pullRequest;
-    private Project forkedProject;
-
-    @Before
-    public void initRepositories() throws IOException, GitAPIException, ServletException,
-            ClientException {
-        GitRepository.setRepoPrefix(REPO_PREFIX);
-        GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX);
-
-        app = support.Helpers.makeTestApplication();
-        Helpers.start(app);
-
-        Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
-        forkedProject = Project.findByOwnerAndProjectName("yobi", "projectYobi-1");
-
-        // 1. projectYobi 저장소를 만듦
-        RepositoryService.createRepository(project);
-
-        // 2. projectYobi 저장소에 커밋 하나
-        {
-            String localRepoPath = LOCAL_REPO_PREFIX + project.name;
-            Git git = Git.cloneRepository()
-                    .setURI(GitRepository.getGitDirectoryURL(project))
-                    .setDirectory(new File(localRepoPath))
-                    .call();
-            Repository repo = git.getRepository();
-            baseCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), "test.txt",
-                    "apple\nbanana\ncat\n", "commit 1");
-            git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call();
-        }
-
-        // 3. 포크된 프로젝트 클론된 저장소 만들기
-        GitRepository.cloneLocalRepository(project, forkedProject);
-
-        // 4. 포크된 저장소에 새 브랜치를 만들어 그 브랜치에 커밋을 두개 하고
-        {
-            String localRepoPath = LOCAL_REPO_PREFIX + forkedProject.name;
-            Git git = Git.cloneRepository()
-                    .setURI(GitRepository.getGitDirectoryURL(forkedProject))
-                    .setDirectory(new File(localRepoPath))
-                    .call();
-            git.branchCreate().setName("fix/1").call();
-            git.checkout().setName("fix/1").call();
-            Repository repo = git.getRepository();
-            assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse();
-            firstCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(),
-                    "test.txt", "apple\nbanana\ncorn\n", "commit 1");
-            secondCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(),
-                    "test.txt", "apple\nbanana\ncake\n", "commit 2");
-            git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call();
-        }
-
-        // 5. 그 브랜치로 projectYobi에 pullrequest를 보낸다.
-        pullRequest = PullRequest.createNewPullRequest(forkedProject, project, "refs/heads/fix/1",
-                "refs/heads/master");
-
-        // 6. attempt merge
-        boolean isConflict = pullRequest.attemptMerge().conflicts();
-
-        assertThat(isConflict).isFalse();
-    }
-
-    @After
-    public void after() {
-        rm_rf(new File(REPO_PREFIX));
-        rm_rf(new File(MERGING_REPO_PREFIX));
-        rm_rf(new File(LOCAL_REPO_PREFIX));
-        Helpers.stop(app);
     }
 
     @Test
test/models/RecentlyVisitedProjectsTest.java
--- test/models/RecentlyVisitedProjectsTest.java
+++ test/models/RecentlyVisitedProjectsTest.java
@@ -20,6 +20,7 @@
  */
 package models;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -45,6 +46,13 @@
         cubrid = Project.findByOwnerAndProjectName("doortts", "CUBRID");
     }
 
+    @After
+    public void after() {
+        for(RecentlyVisitedProjects visitedProjects: RecentlyVisitedProjects.find.all()) {
+            visitedProjects.delete();
+        }
+    }
+
     @Test
     public void addVisit() {
         // When
test/models/UserTest.java
--- test/models/UserTest.java
+++ test/models/UserTest.java
@@ -197,5 +197,8 @@
         // Then
         issue.refresh();
         assertThat(issue.assignee).isNull();
+
+        // To keep data clean after this test.
+        user.delete();
     }
 }
test/models/WatchTest.java
--- test/models/WatchTest.java
+++ test/models/WatchTest.java
@@ -35,19 +35,17 @@
 import static play.test.Helpers.start;
 import static play.test.Helpers.stop;
 
-public class WatchTest {
-
-    private FakeApplication application;
+public class WatchTest extends ModelTest<Watch> {
 
     @Before
-    public void setUp() {
-        application = support.Helpers.makeTestApplication();
-        start(application);
-    }
+    public void setup() {
+        for(Watch watch : Watch.find.all()) {
+            watch.delete();
+        }
 
-    @After
-    public void tearDown() {
-        stop(application);
+        for(Unwatch unwatch : Unwatch.find.all()) {
+            unwatch.delete();
+        }
     }
 
     @Test
test/models/support/ReviewSearchConditionTest.java
--- test/models/support/ReviewSearchConditionTest.java
+++ test/models/support/ReviewSearchConditionTest.java
@@ -34,7 +34,20 @@
  */
 public class ReviewSearchConditionTest extends ModelTest<ReviewSearchCondition> {
 
-    protected static FakeApplication app;
+    CommentThread ct1;
+    CommentThread ct2;
+    CommentThread ct3;
+
+    @Before
+    public void before() {
+        addTestData();
+    }
+
+    @After
+    public void after() {
+        clearData();
+    }
+
 
     /**
      * Tests searching reviews having the content.
@@ -160,12 +173,18 @@
         User lazielUser = User.findByLoginId("laziel");
         Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
 
-        addTestThread1(adminUser, lazielUser, project);
-        addTestThread2(adminUser, lazielUser, project);
-        addTestThread3(adminUser, lazielUser, project);
+        ct1 = addTestThread1(adminUser, lazielUser, project);
+        ct2 = addTestThread2(adminUser, lazielUser, project);
+        ct3 = addTestThread3(adminUser, lazielUser, project);
     }
 
-    private void addTestThread1(User admin, User user, Project project) {
+    private void clearData() {
+        ct1.delete();
+        ct2.delete();
+        ct3.delete();
+    }
+
+    private CommentThread addTestThread1(User admin, User user, Project project) {
         CodeCommentThread thread = new CodeCommentThread();
         thread.createdDate = JodaDateUtil.today();
         thread.commitId = "controllers";
@@ -173,9 +192,10 @@
         makeThread(admin, "Comment #1 : 111", project, thread);
         makeComment(thread, user, "Comment #1-1");
         makeComment(thread, user, "Comment #1-2");
+        return thread;
     }
 
-    private void addTestThread2(User admin, User user, Project project) {
+    private CommentThread addTestThread2(User admin, User user, Project project) {
         CodeCommentThread thread = new CodeCommentThread();
         thread.createdDate = JodaDateUtil.before(2);
         thread.commitId = "200";
@@ -183,9 +203,10 @@
         makeThread(admin, "Comment #2 : /app/controllers/BoardApp.java", project, thread);
         makeComment(thread, admin, "Comment #2-1");
         makeComment(thread, user, "Comment #2-2");
+        return thread;
     }
 
-    private void addTestThread3(User admin, User user, Project project) {
+    private CommentThread addTestThread3(User admin, User user, Project project) {
         CodeCommentThread thread = new CodeCommentThread();
         thread.createdDate = JodaDateUtil.before(3);
         thread.commitId = "300";
@@ -195,21 +216,8 @@
         makeComment(thread, user, "Comment #3-1");
         makeComment(thread, user, "Comment #3-2");
         makeComment(thread, user, "Comment #3-3");
+        return thread;
     }
-
-
-    @Before
-    public void before() {
-        app = support.Helpers.makeTestApplication();
-        Helpers.start(app);
-        addTestData();
-    }
-
-    @After
-    public void after() {
-        Helpers.stop(app);
-    }
-
     /**
      * Creates a comment and added to {@code thread}
      * @param thread
test/playRepository/CommitTest.java
--- test/playRepository/CommitTest.java
+++ test/playRepository/CommitTest.java
@@ -30,6 +30,17 @@
 import org.junit.*;
 
 public class CommitTest extends ModelTest<Commit> {
+
+    @Before
+    public void before() {
+        for(Watch watch : Watch.find.all()) {
+            watch.delete();
+        }
+        for(Unwatch unwatch : Unwatch.find.all()) {
+            unwatch.delete();
+        }
+    }
+
     @Test
     public void getWatchers_no_watchers() {
         // Given
@@ -77,6 +88,7 @@
 
         // Then
         assertThat(watchers).containsOnly(author, commentUser);
+        comment.delete();
     }
 
     @Test
test/playRepository/GitRepositoryTest.java
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
@@ -41,6 +41,7 @@
 import org.junit.rules.TestWatcher;
 import play.test.FakeApplication;
 import play.test.Helpers;
+import support.ExecutionTimeWatcher;
 
 import javax.naming.LimitExceededException;
 import java.io.BufferedWriter;
test/support/Files.java
--- test/support/Files.java
+++ test/support/Files.java
@@ -32,7 +32,6 @@
                 rm_rf(f);
             }
         }
-        System.gc();
         file.delete();
     }
 }
Add a comment
List