MCPcopy Index your code
hub / github.com/OpenFeign/feign / BaseBuilderTest

Class BaseBuilderTest

core/src/test/java/feign/BaseBuilderTest.java:27–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25import org.mockito.Mockito;
26
27class BaseBuilderTest {
28
29 @Test
30 void checkEnrichTouchesAllAsyncBuilderFields()
31 throws IllegalArgumentException, IllegalAccessException {
32 test(
33 AsyncFeign.builder().requestInterceptor(_ -> {}).responseInterceptor((ic, c) -> c.next(ic)),
34 12);
35 }
36
37 private void test(BaseBuilder<?, ?> builder, int expectedFieldsCount)
38 throws IllegalArgumentException, IllegalAccessException {
39 Capability mockingCapability = Mockito.mock(Capability.class, RETURNS_MOCKS);
40 BaseBuilder<?, ?> enriched = builder.addCapability(mockingCapability).enrich();
41
42 List<Field> fields = enriched.getFieldsToEnrich();
43 assertThat(fields).hasSize(expectedFieldsCount);
44
45 for (Field field : fields) {
46 field.setAccessible(true);
47 Object mockedValue = field.get(enriched);
48 if (mockedValue instanceof List<?> list) {
49 assertThat(list).withFailMessage("Enriched list missing contents %s", field).isNotEmpty();
50 mockedValue = list.getFirst();
51 }
52 assertThat(Mockito.mockingDetails(mockedValue).isMock())
53 .as("Field was not enriched " + field)
54 .isTrue();
55 assertNotSame(builder, enriched);
56 }
57 }
58
59 @Test
60 void checkEnrichTouchesAllBuilderFields()
61 throws IllegalArgumentException, IllegalAccessException {
62 test(
63 Feign.builder().requestInterceptor(_ -> {}).responseInterceptor((ic, c) -> c.next(ic)), 10);
64 }
65}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected