View Javadoc
1   /*
2    * Copyright (C) 2012, IBM Corporation and others. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
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  }