You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SquashCommitMsgTest.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. import static java.nio.charset.StandardCharsets.UTF_8;
  12. import static org.junit.Assert.assertEquals;
  13. import static org.junit.Assert.assertFalse;
  14. import java.io.File;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17. import org.eclipse.jgit.junit.RepositoryTestCase;
  18. import org.junit.Test;
  19. public class SquashCommitMsgTest extends RepositoryTestCase {
  20. private static final String squashMsg = "squashed commit";
  21. @Test
  22. public void testReadWriteMergeMsg() throws IOException {
  23. assertEquals(db.readSquashCommitMsg(), null);
  24. assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
  25. db.writeSquashCommitMsg(squashMsg);
  26. assertEquals(squashMsg, db.readSquashCommitMsg());
  27. assertEquals(read(new File(db.getDirectory(), Constants.SQUASH_MSG)),
  28. squashMsg);
  29. db.writeSquashCommitMsg(null);
  30. assertEquals(db.readSquashCommitMsg(), null);
  31. assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
  32. try (FileOutputStream fos = new FileOutputStream(
  33. new File(db.getDirectory(), Constants.SQUASH_MSG))) {
  34. fos.write(squashMsg.getBytes(UTF_8));
  35. }
  36. assertEquals(db.readSquashCommitMsg(), squashMsg);
  37. }
  38. }