RefUpdateTest: Refactor to not use deprecated Repository#getAllRefs
Change-Id: I157e62a0e1479d4bc95ef867e616ca8a30041759 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
f7fbc7fcd7
commit
5ff56d2ed1
|
@ -62,6 +62,7 @@
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jgit.lib.AnyObjectId;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
|
@ -110,11 +111,21 @@ private void delete(final RefUpdate ref, final Result expected,
|
|||
delete(db, ref, expected, exists, removed);
|
||||
}
|
||||
|
||||
private void delete(Repository repo, final RefUpdate ref, final Result expected,
|
||||
final boolean exists, final boolean removed) throws IOException {
|
||||
assertEquals(exists, repo.getAllRefs().containsKey(ref.getName()));
|
||||
private void delete(Repository repo, final RefUpdate ref,
|
||||
final Result expected, final boolean exists, final boolean removed)
|
||||
throws IOException {
|
||||
assertEquals(exists, getRef(repo, ref.getName()).isPresent());
|
||||
assertEquals(expected, ref.delete());
|
||||
assertEquals(!removed, repo.getAllRefs().containsKey(ref.getName()));
|
||||
assertEquals(!removed, getRef(repo, ref.getName()).isPresent());
|
||||
}
|
||||
|
||||
private Optional<Ref> getRef(Repository repo, String name)
|
||||
throws IOException {
|
||||
return getRef(repo.getRefDatabase().getRefs(), name);
|
||||
}
|
||||
|
||||
private Optional<Ref> getRef(List<Ref> refs, String name) {
|
||||
return refs.stream().filter(r -> r.getName().equals(name)).findAny();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,8 +136,7 @@ public void testNoCacheObjectIdSubclass() throws IOException {
|
|||
ru.setNewObjectId(newid);
|
||||
Result update = ru.update();
|
||||
assertEquals(Result.NEW, update);
|
||||
final Ref r = db.getAllRefs().get(newRef);
|
||||
assertNotNull(r);
|
||||
final Ref r = getRef(db, newRef).get();
|
||||
assertEquals(newRef, r.getName());
|
||||
assertNotNull(r.getObjectId());
|
||||
assertNotSame(newid, r.getObjectId());
|
||||
|
@ -378,10 +388,10 @@ public void testDeleteWithoutHead() throws IOException {
|
|||
|
||||
@Test
|
||||
public void testRefKeySameAsName() {
|
||||
@SuppressWarnings("deprecation")
|
||||
Map<String, Ref> allRefs = db.getAllRefs();
|
||||
for (Entry<String, Ref> e : allRefs.entrySet()) {
|
||||
assertEquals(e.getKey(), e.getValue().getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,8 +530,8 @@ public void testUpdateRefNoChange() throws IOException {
|
|||
*/
|
||||
@Test
|
||||
public void testRefsCacheAfterUpdate() throws Exception {
|
||||
// Do not use the defalt repo for this case.
|
||||
Map<String, Ref> allRefs = db.getAllRefs();
|
||||
// Do not use the default repo for this case.
|
||||
List<Ref> allRefs = db.getRefDatabase().getRefs();
|
||||
ObjectId oldValue = db.resolve("HEAD");
|
||||
ObjectId newValue = db.resolve("HEAD^");
|
||||
// first make HEAD refer to loose ref
|
||||
|
@ -537,9 +547,9 @@ public void testRefsCacheAfterUpdate() throws Exception {
|
|||
update = updateRef.update();
|
||||
assertEquals(Result.FAST_FORWARD, update);
|
||||
|
||||
allRefs = db.getAllRefs();
|
||||
Ref master = allRefs.get("refs/heads/master");
|
||||
Ref head = allRefs.get("HEAD");
|
||||
allRefs = db.getRefDatabase().getRefs();
|
||||
Ref master = getRef(allRefs, "refs/heads/master").get();
|
||||
Ref head = getRef(allRefs, "HEAD").get();
|
||||
assertEquals("refs/heads/master", master.getName());
|
||||
assertEquals("HEAD", head.getName());
|
||||
assertTrue("is symbolic reference", head.isSymbolic());
|
||||
|
@ -557,8 +567,8 @@ public void testRefsCacheAfterUpdate() throws Exception {
|
|||
*/
|
||||
@Test
|
||||
public void testRefsCacheAfterUpdateLooseOnly() throws Exception {
|
||||
// Do not use the defalt repo for this case.
|
||||
Map<String, Ref> allRefs = db.getAllRefs();
|
||||
// Do not use the default repo for this case.
|
||||
List<Ref> allRefs = db.getRefDatabase().getRefs();
|
||||
ObjectId oldValue = db.resolve("HEAD");
|
||||
writeSymref(Constants.HEAD, "refs/heads/newref");
|
||||
RefUpdate updateRef = db.updateRef(Constants.HEAD);
|
||||
|
@ -567,9 +577,9 @@ public void testRefsCacheAfterUpdateLooseOnly() throws Exception {
|
|||
Result update = updateRef.update();
|
||||
assertEquals(Result.NEW, update);
|
||||
|
||||
allRefs = db.getAllRefs();
|
||||
Ref head = allRefs.get("HEAD");
|
||||
Ref newref = allRefs.get("refs/heads/newref");
|
||||
allRefs = db.getRefDatabase().getRefs();
|
||||
Ref head = getRef(allRefs, "HEAD").get();
|
||||
Ref newref = getRef(allRefs, "refs/heads/newref").get();
|
||||
assertEquals("refs/heads/newref", newref.getName());
|
||||
assertEquals("HEAD", head.getName());
|
||||
assertTrue("is symbolic reference", head.isSymbolic());
|
||||
|
|
Loading…
Reference in New Issue