PagedTemplatesSpliterator.java

1
package com.fwmotion.threescale.cms.support;
2
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.fwmotion.threescale.cms.mappers.CmsTemplateMapper;
5
import com.fwmotion.threescale.cms.model.CmsTemplate;
6
import com.redhat.threescale.rest.cms.ApiException;
7
import com.redhat.threescale.rest.cms.api.TemplatesApi;
8
import com.redhat.threescale.rest.cms.model.TemplateList;
9
import jakarta.annotation.Nonnull;
10
import jakarta.annotation.Nullable;
11
import jakarta.validation.constraints.Positive;
12
import jakarta.validation.constraints.PositiveOrZero;
13
import org.apache.commons.collections4.ListUtils;
14
import org.mapstruct.factory.Mappers;
15
16
import java.util.*;
17
import java.util.stream.Collectors;
18
19
public class PagedTemplatesSpliterator extends AbstractPagedRestApiSpliterator<CmsTemplate> {
20
21
    private static final CmsTemplateMapper TEMPLATE_MAPPER = Mappers.getMapper(CmsTemplateMapper.class);
22
23
    private final TemplatesApi templatesApi;
24
    private final boolean includeContent;
25
26
    public PagedTemplatesSpliterator(@Nonnull TemplatesApi templatesApi,
27
                                     @Nonnull ObjectMapper objectMapper,
28
                                     boolean includeContent) {
29
        super(Collections.emptySet(), objectMapper, 0);
30
        this.templatesApi = templatesApi;
31
        this.includeContent = includeContent;
32
    }
33
34
    public PagedTemplatesSpliterator(@Nonnull TemplatesApi templatesApi,
35
                                     @Nonnull ObjectMapper objectMapper,
36
                                     boolean includeContent,
37
                                     @Positive int requestedPageSize) {
38
        super(requestedPageSize, objectMapper, Collections.emptySet(), 0);
39
        this.templatesApi = templatesApi;
40
        this.includeContent = includeContent;
41
    }
42
43
    private PagedTemplatesSpliterator(@Nonnull TemplatesApi templatesApi,
44
                                      @Nonnull ObjectMapper objectMapper,
45
                                      boolean includeContent,
46
                                      @Positive int requestedPageSize,
47
                                      @Nonnull Collection<CmsTemplate> currentPage,
48
                                      @PositiveOrZero int currentPageNumber) {
49
        super(requestedPageSize, objectMapper, currentPage, currentPageNumber);
50
        this.templatesApi = templatesApi;
51
        this.includeContent = includeContent;
52
    }
53
54
    @Nullable
55
    @Override
56
    protected Collection<CmsTemplate> getPage(@PositiveOrZero int pageNumber,
57
                                              @Positive int pageSize) {
58
        try {
59
            TemplateList templateList = templatesApi.listTemplates(
60
                pageNumber,
61
                pageSize,
62
                includeContent
63
            );
64
65
            List<CmsTemplate> resultPage = ListUtils
66
                .emptyIfNull(templateList.getCollection())
67
                .stream()
68
                .map(TEMPLATE_MAPPER::fromRest)
69
                .sorted(getComparator())
70
                .collect(Collectors.toList());
71
72 1 1. getPage : removed call to com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::validateResultPageSize → SURVIVED
            validateResultPageSize(
73
                "template",
74
                pageNumber,
75
                pageSize,
76
                resultPage,
77
                templateList.getMetadata());
78
79 1 1. getPage : replaced return value with Collections.emptyList for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::getPage → KILLED
            return resultPage;
80
        } catch (ApiException e) {
81
            throw handleApiException(e, "template", pageNumber, pageSize);
82
        }
83
    }
84
85
    @Nonnull
86
    @Override
87
    protected AbstractPagedRestApiSpliterator<CmsTemplate> doSplit(
88
        @Positive int requestedPageSize,
89
        @Nonnull Collection<CmsTemplate> currentPage,
90
        @PositiveOrZero int currentPageNumber
91
    ) {
92 1 1. doSplit : replaced return value with null for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::doSplit → KILLED
        return new PagedTemplatesSpliterator(
93
            templatesApi,
94
            getObjectMapper(),
95
            includeContent,
96
            requestedPageSize,
97
            currentPage,
98
            currentPageNumber
99
        );
100
    }
101
102
    @Override
103
    public int characteristics() {
104 1 1. characteristics : replaced int return with 0 for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::characteristics → SURVIVED
        return Spliterator.DISTINCT |
105
            Spliterator.SORTED |
106
            Spliterator.ORDERED |
107
            Spliterator.NONNULL |
108
            Spliterator.IMMUTABLE;
109
    }
110
111
    @Nonnull
112
    @Override
113
    public Comparator<? super CmsTemplate> getComparator() {
114 1 1. getComparator : replaced return value with null for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::getComparator → KILLED
        return Comparator.comparing(CmsTemplate::getId);
115
    }
116
}

Mutations

72

1.1
Location : getPage
Killed by : none
removed call to com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::validateResultPageSize → SURVIVED

79

1.1
Location : getPage
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
replaced return value with Collections.emptyList for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::getPage → KILLED

92

1.1
Location : doSplit
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
replaced return value with null for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::doSplit → KILLED

104

1.1
Location : characteristics
Killed by : none
replaced int return with 0 for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::characteristics → SURVIVED

114

1.1
Location : getComparator
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
replaced return value with null for com/fwmotion/threescale/cms/support/PagedTemplatesSpliterator::getComparator → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.3