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.

UploadPackRefSortingForReachabilityTest.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (C) 2019, Google LLC. 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.transport;
  11. import static org.hamcrest.MatcherAssert.assertThat;
  12. import static org.hamcrest.Matchers.contains;
  13. import java.util.List;
  14. import java.util.stream.Collectors;
  15. import java.util.stream.Stream;
  16. import org.eclipse.jgit.lib.ObjectId;
  17. import org.eclipse.jgit.lib.ObjectIdRef.Unpeeled;
  18. import org.eclipse.jgit.lib.Ref;
  19. import org.eclipse.jgit.lib.Ref.Storage;
  20. import org.junit.Test;
  21. public class UploadPackRefSortingForReachabilityTest {
  22. @Test
  23. public void sortReferences() {
  24. List<Ref> refs = Stream.of("refs/changes/12/12", "refs/changes/12/1",
  25. "refs/heads/master", "refs/heads/something",
  26. "refs/changes/55/1", "refs/tags/v1.1")
  27. .map(s -> new Unpeeled(Storage.LOOSE, s, ObjectId.zeroId()))
  28. .collect(Collectors.toList());
  29. Stream<Ref> sorted = UploadPack.importantRefsFirst(refs);
  30. List<String> collected = sorted.map(Ref::getName)
  31. .collect(Collectors.toList());
  32. assertThat(collected,
  33. contains("refs/heads/master", "refs/heads/something",
  34. "refs/tags/v1.1", "refs/changes/12/12",
  35. "refs/changes/12/1", "refs/changes/55/1"));
  36. }
  37. }