Skip to content

Commit 8689c1b

Browse files
committed
DATAREST-1446 - Polishing.
Test cases. Original pull request: #366.
1 parent 694079d commit 8689c1b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/DefaultExcerptProjector.java

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public Object projectExcerpt(Object source) {
6464
public boolean hasExcerptProjection(Class<?> type) {
6565

6666
ResourceMetadata metadata = mappings.getMetadataFor(type);
67+
6768
return metadata == null ? false : metadata.getExcerptProjection().isPresent();
6869
}
6970
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)