|
| 1 | +/* |
| 2 | + * Copyright 2019 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.rest.webmvc.support; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.*; |
| 19 | +import static org.mockito.Mockito.*; |
| 20 | + |
| 21 | +import java.util.Optional; |
| 22 | + |
| 23 | +import org.junit.Test; |
| 24 | +import org.springframework.data.projection.ProjectionFactory; |
| 25 | +import org.springframework.data.rest.core.mapping.ResourceMappings; |
| 26 | +import org.springframework.data.rest.core.mapping.ResourceMetadata; |
| 27 | + |
| 28 | +/** |
| 29 | + * Unit test for {@link DefaultExcerptProjector}. |
| 30 | + * |
| 31 | + * @author Oliver Drotbohm |
| 32 | + */ |
| 33 | +public class DefaultExcerptProjectorUnitTests { |
| 34 | + |
| 35 | + ProjectionFactory factory = mock(ProjectionFactory.class); |
| 36 | + ResourceMappings mappings = mock(ResourceMappings.class); |
| 37 | + ResourceMetadata metadata = mock(ResourceMetadata.class); |
| 38 | + |
| 39 | + @Test // DATAREST-1446 |
| 40 | + public void doesNotHaveExcerptProjectionIfMetadataReturnsNone() { |
| 41 | + |
| 42 | + when(mappings.getMetadataFor(Object.class)).thenReturn(metadata); |
| 43 | + when(metadata.getExcerptProjection()).thenReturn(Optional.empty()); |
| 44 | + |
| 45 | + DefaultExcerptProjector projector = new DefaultExcerptProjector(factory, mappings); |
| 46 | + |
| 47 | + assertThat(projector.hasExcerptProjection(Object.class)).isFalse(); |
| 48 | + } |
| 49 | +} |
0 commit comments