1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.lib;
11
12 import static java.nio.charset.StandardCharsets.UTF_8;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15
16 import java.io.File;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
19
20 import org.eclipse.jgit.junit.RepositoryTestCase;
21 import org.junit.Test;
22
23 public class SquashCommitMsgTest extends RepositoryTestCase {
24 private static final String squashMsg = "squashed commit";
25
26 @Test
27 public void testReadWriteMergeMsg() throws IOException {
28 assertEquals(db.readSquashCommitMsg(), null);
29 assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
30 db.writeSquashCommitMsg(squashMsg);
31 assertEquals(squashMsg, db.readSquashCommitMsg());
32 assertEquals(read(new File(db.getDirectory(), Constants.SQUASH_MSG)),
33 squashMsg);
34 db.writeSquashCommitMsg(null);
35 assertEquals(db.readSquashCommitMsg(), null);
36 assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
37 try (FileOutputStream fos = new FileOutputStream(
38 new File(db.getDirectory(), Constants.SQUASH_MSG))) {
39 fos.write(squashMsg.getBytes(UTF_8));
40 }
41 assertEquals(db.readSquashCommitMsg(), squashMsg);
42 }
43 }