Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ObjectIdMatcher.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2018, 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 java.util.Collection;
  12. import java.util.Set;
  13. import java.util.stream.Collectors;
  14. import org.eclipse.jgit.lib.ObjectId;
  15. import org.eclipse.jgit.lib.Sets;
  16. import org.hamcrest.Description;
  17. import org.hamcrest.Matcher;
  18. import org.hamcrest.TypeSafeMatcher;
  19. /**
  20. * Multiple tests check that a collection of ObjectIds contain certain SHA1
  21. * (written as strings). This matcher hides the ObjectId to string conversion to
  22. * make the assertion more readable:
  23. *
  24. * assertThat(req.getWantsIds(), hasOnlyObjectIds("123123", "234234"));
  25. */
  26. class ObjectIdMatcher extends TypeSafeMatcher<Collection<ObjectId>> {
  27. private final Set<ObjectId> expectedOids;
  28. private ObjectIdMatcher(Set<String> oids) {
  29. this.expectedOids = oids.stream().map(ObjectId::fromString)
  30. .collect(Collectors.toSet());
  31. }
  32. @Override
  33. public void describeTo(Description desc) {
  34. desc.appendText("Object ids:");
  35. desc.appendValueList("<", ",", ">", expectedOids);
  36. }
  37. @Override
  38. protected boolean matchesSafely(Collection<ObjectId> resultOids) {
  39. return resultOids.containsAll(expectedOids)
  40. && expectedOids.containsAll(resultOids);
  41. }
  42. /**
  43. * Assert that all and only the received {@link ObjectId object ids} are in
  44. * the expected set.
  45. * <p>
  46. * ObjectIds are compared by SHA1.
  47. *
  48. * @param oids
  49. * Object ids to examine.
  50. * @return true if examined and specified sets contains exactly the same
  51. * elements.
  52. */
  53. static Matcher<Collection<ObjectId>> hasOnlyObjectIds(
  54. String... oids) {
  55. return new ObjectIdMatcher(Sets.of(oids));
  56. }
  57. }