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.

NotesCommandTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com> 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.api;
  11. import static java.nio.charset.StandardCharsets.UTF_8;
  12. import static org.junit.Assert.assertEquals;
  13. import java.util.List;
  14. import org.eclipse.jgit.junit.RepositoryTestCase;
  15. import org.eclipse.jgit.notes.Note;
  16. import org.eclipse.jgit.revwalk.RevCommit;
  17. import org.junit.Before;
  18. import org.junit.Test;
  19. public class NotesCommandTest extends RepositoryTestCase {
  20. private Git git;
  21. private RevCommit commit1, commit2;
  22. private static final String FILE = "test.txt";
  23. @Override
  24. @Before
  25. public void setUp() throws Exception {
  26. super.setUp();
  27. git = new Git(db);
  28. // commit something
  29. writeTrashFile(FILE, "Hello world");
  30. git.add().addFilepattern(FILE).call();
  31. commit1 = git.commit().setMessage("Initial commit").call();
  32. git.rm().addFilepattern(FILE).call();
  33. commit2 = git.commit().setMessage("Removed file").call();
  34. git.notesAdd().setObjectId(commit1)
  35. .setMessage("data").call();
  36. }
  37. @Test
  38. public void testListNotes() throws Exception {
  39. List<Note> notes = git.notesList().call();
  40. assertEquals(1, notes.size());
  41. }
  42. @Test
  43. public void testAddAndRemoveNote() throws Exception {
  44. git.notesAdd().setObjectId(commit2).setMessage("data").call();
  45. Note note = git.notesShow().setObjectId(commit2).call();
  46. String content = new String(db.open(note.getData()).getCachedBytes(),
  47. UTF_8);
  48. assertEquals(content, "data");
  49. git.notesRemove().setObjectId(commit2).call();
  50. List<Note> notes = git.notesList().call();
  51. assertEquals(1, notes.size());
  52. }
  53. }