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