Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRené Scheibe2018-09-03 21:21:10 +0000
committerRené Scheibe2018-09-03 21:21:10 +0000
commit685f8c8dbe9e2f1e139a55970588f92d5482b3ba (patch)
treea9cd6cc3dca2e49c38c9ef71efd48f0d4d79611a
parenta3cb474c94cb8a75b6dfc13ad36cd855ae969852 (diff)
downloadjgit-685f8c8dbe9e2f1e139a55970588f92d5482b3ba.tar.gz
jgit-685f8c8dbe9e2f1e139a55970588f92d5482b3ba.tar.xz
jgit-685f8c8dbe9e2f1e139a55970588f92d5482b3ba.zip
Simplify file creation in ResetCommandTest
Use existing test utility methods instead of nested PrintWriter usage. Change-Id: I324852c7971ae644fa499f377a31d1cf265c7fd9 Signed-off-by: René Scheibe <rene.scheibe@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java55
1 files changed, 17 insertions, 38 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index e10a91c5d8..2b97b307bf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2013, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2011-2018, Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -52,7 +52,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
-import java.io.PrintWriter;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -94,45 +93,25 @@ public class ResetCommandTest extends RepositoryTestCase {
git = new Git(db);
initialCommit = git.commit().setMessage("initial commit").call();
+ // create file
+ indexFile = writeTrashFile("a.txt", "content");
+
// create nested file
- File dir = new File(db.getWorkTree(), "dir");
- FileUtils.mkdir(dir);
- File nestedFile = new File(dir, "b.txt");
- FileUtils.createNewFile(nestedFile);
-
- try (PrintWriter nestedFileWriter = new PrintWriter(nestedFile)) {
- nestedFileWriter.print("content");
- nestedFileWriter.flush();
-
- // create file
- indexFile = new File(db.getWorkTree(), "a.txt");
- FileUtils.createNewFile(indexFile);
- try (PrintWriter writer = new PrintWriter(indexFile)) {
- writer.print("content");
- writer.flush();
-
- // add file and commit it
- git.add().addFilepattern("dir").addFilepattern("a.txt").call();
- secondCommit = git.commit()
- .setMessage("adding a.txt and dir/b.txt").call();
-
- prestage = DirCache.read(db.getIndexFile(), db.getFS())
- .getEntry(indexFile.getName());
-
- // modify file and add to index
- writer.print("new content");
- }
- nestedFileWriter.print("new content");
- }
- git.add().addFilepattern("a.txt").addFilepattern("dir").call();
+ writeTrashFile("dir/b.txt", "content");
+
+ // add files and commit them
+ git.add().addFilepattern("a.txt").addFilepattern("dir/b.txt").call();
+ secondCommit = git.commit().setMessage("adding a.txt and dir/b.txt").call();
+
+ prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(indexFile.getName());
+
+ // modify files and add to index
+ writeTrashFile("a.txt", "new content");
+ writeTrashFile("dir/b.txt", "new content");
+ git.add().addFilepattern("a.txt").addFilepattern("dir/b.txt").call();
// create a file not added to the index
- untrackedFile = new File(db.getWorkTree(),
- "notAddedToIndex.txt");
- FileUtils.createNewFile(untrackedFile);
- try (PrintWriter writer2 = new PrintWriter(untrackedFile)) {
- writer2.print("content");
- }
+ untrackedFile = writeTrashFile("notAddedToIndex.txt", "content");
}
@Test

Back to the top