/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ExposedFieldsUnitTests.java

https://github.com/spring-projects/spring-data-mongodb · Java · 56 lines · 25 code · 10 blank · 21 comment · 0 complexity · 2471a777efcfe52a91d46921afe4eb2a MD5 · raw file

  1. /*
  2. * Copyright 2013-2022 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.data.mongodb.core.aggregation;
  17. import static org.assertj.core.api.Assertions.*;
  18. import org.junit.jupiter.api.Test;
  19. import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
  20. /**
  21. * Unit tests for {@link ExposedFields}.
  22. *
  23. * @author Oliver Gierke
  24. * @author Thomas Darimont
  25. */
  26. public class ExposedFieldsUnitTests {
  27. @Test
  28. public void rejectsNullFields() {
  29. assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.from((ExposedField) null));
  30. }
  31. @Test
  32. public void rejectsNullFieldsForSynthetics() {
  33. assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.synthetic(null));
  34. }
  35. @Test
  36. public void rejectsNullFieldsForNonSynthetics() {
  37. assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.nonSynthetic(null));
  38. }
  39. @Test
  40. public void exposesSingleField() {
  41. ExposedFields fields = ExposedFields.synthetic(Fields.fields("foo"));
  42. assertThat(fields.exposesSingleFieldOnly()).isTrue();
  43. fields = fields.and(new ExposedField("bar", true));
  44. assertThat(fields.exposesSingleFieldOnly()).isFalse();
  45. }
  46. }