Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RefDatabaseConflictingNamesTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2013, Robin Stocker <robin@nibor.org> 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 org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertTrue;
  13. import java.io.IOException;
  14. import java.util.Arrays;
  15. import java.util.Collections;
  16. import java.util.HashMap;
  17. import java.util.HashSet;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.junit.Test;
  22. public class RefDatabaseConflictingNamesTest {
  23. private RefDatabase refDatabase = new RefDatabase() {
  24. @Override
  25. public Map<String, Ref> getRefs(String prefix) throws IOException {
  26. if (ALL.equals(prefix)) {
  27. Map<String, Ref> existing = new HashMap<>();
  28. existing.put("refs/heads/a/b", null /* not used */);
  29. existing.put("refs/heads/q", null /* not used */);
  30. return existing;
  31. }
  32. return Collections.emptyMap();
  33. }
  34. @Override
  35. public Ref peel(Ref ref) throws IOException {
  36. return null;
  37. }
  38. @Override
  39. public RefUpdate newUpdate(String name, boolean detach)
  40. throws IOException {
  41. return null;
  42. }
  43. @Override
  44. public RefRename newRename(String fromName, String toName)
  45. throws IOException {
  46. return null;
  47. }
  48. @Override
  49. public boolean isNameConflicting(String name) throws IOException {
  50. return false;
  51. }
  52. @Override
  53. public Ref exactRef(String name) throws IOException {
  54. return null;
  55. }
  56. @Override
  57. public List<Ref> getAdditionalRefs() throws IOException {
  58. return null;
  59. }
  60. @Override
  61. public void create() throws IOException {
  62. // Not needed
  63. }
  64. @Override
  65. public void close() {
  66. // Not needed
  67. }
  68. };
  69. @Test
  70. public void testGetConflictingNames() throws IOException {
  71. // new references cannot replace an existing container
  72. assertConflictingNames("refs", "refs/heads/a/b", "refs/heads/q");
  73. assertConflictingNames("refs/heads", "refs/heads/a/b", "refs/heads/q");
  74. assertConflictingNames("refs/heads/a", "refs/heads/a/b");
  75. // existing reference is not conflicting
  76. assertNoConflictingNames("refs/heads/a/b");
  77. // new references are not conflicting
  78. assertNoConflictingNames("refs/heads/a/d");
  79. assertNoConflictingNames("refs/heads/master");
  80. // existing reference must not be used as a container
  81. assertConflictingNames("refs/heads/a/b/c", "refs/heads/a/b");
  82. assertConflictingNames("refs/heads/q/master", "refs/heads/q");
  83. }
  84. private void assertNoConflictingNames(String proposed) throws IOException {
  85. assertTrue("expected conflicting names to be empty", refDatabase
  86. .getConflictingNames(proposed).isEmpty());
  87. }
  88. private void assertConflictingNames(String proposed, String... conflicts)
  89. throws IOException {
  90. Set<String> expected = new HashSet<>(Arrays.asList(conflicts));
  91. assertEquals(expected,
  92. new HashSet<>(refDatabase.getConflictingNames(proposed)));
  93. }
  94. }