com.hltech.pact.gen.domain.client.model.ResponseRepresentation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultForMethod(Method,String[]) 0 7 1
A from(HttpStatus,List,Method,String,boolean) 0 17 1
1
package com.hltech.pact.gen.domain.client.model;
2
3
import com.hltech.pact.gen.domain.client.util.RawHeadersParser;
4
import com.hltech.pact.gen.domain.client.util.TypeExtractor;
5
import lombok.Builder;
6
import lombok.Data;
7
import org.springframework.http.HttpStatus;
8
9
import java.lang.reflect.Method;
10
import java.util.List;
11
12
@Data
13
@Builder
14
public class ResponseRepresentation {
15
16
    private final HttpStatus status;
17
    private final List<Param> headers;
18
    private final Body body;
19
    private final String description;
20
    private final boolean emptyBodyExpected;
21
22
    public static ResponseRepresentation getDefaultForMethod(Method method, String[] responseHeaders) {
23
        return ResponseRepresentation.from(
24
            HttpStatus.OK,
25
            RawHeadersParser.parseAll(responseHeaders),
26
            method,
27
            "",
28
            false);
29
    }
30
31
    public static ResponseRepresentation from(HttpStatus status,
32
                                                          List<Param> headers,
33
                                                          Method method,
34
                                                          String description,
35
                                                          boolean isEmptyBodyExpected) {
36
37
        return ResponseRepresentation.builder()
38
            .status(status)
39
            .headers(headers)
40
            .body(Body.builder()
41
                .type(method.getReturnType())
42
                .genericArgumentTypes(
43
                    TypeExtractor.extractParameterTypesFromType(method.getGenericReturnType()))
44
                .build())
45
            .description(description)
46
            .emptyBodyExpected(isEmptyBodyExpected)
47
            .build();
48
    }
49
}
50