|
| 1 | +package life.qbic.compass.model |
| 2 | + |
| 3 | +import spock.lang.Specification |
| 4 | +import spock.lang.Unroll |
| 5 | + |
| 6 | +class SignPostingResultSpec extends Specification { |
| 7 | + |
| 8 | + @Unroll |
| 9 | + def "stable API: method '#methodName' is available with return type '#returnType.simpleName' and params #paramTypes*.simpleName"() { |
| 10 | + when: |
| 11 | + def method = SignPostingResult.getMethod(methodName, paramTypes as Class[]) |
| 12 | + |
| 13 | + then: |
| 14 | + method != null |
| 15 | + method.returnType == returnType |
| 16 | + |
| 17 | + where: |
| 18 | + methodName | returnType | paramTypes |
| 19 | + "signPostingView" | SignPostingView | ([] as Class[]) |
| 20 | + "issueReport" | life.qbic.linksmith.spi.WebLinkValidator.IssueReport | ([] as Class[]) |
| 21 | + "level2LinksetView" | Level2LinksetView | ([] as Class[]) |
| 22 | + "hasLinkSetView" | boolean | ([] as Class[]) |
| 23 | + "hasIssues" | boolean | ([] as Class[]) |
| 24 | + "hasErrors" | boolean | ([] as Class[]) |
| 25 | + "hasWarnings" | boolean | ([] as Class[]) |
| 26 | + "withoutLinksetView" | SignPostingResult | ([SignPostingView, life.qbic.linksmith.spi.WebLinkValidator.IssueReport] as Class[]) |
| 27 | + "withLinksetView" | SignPostingResult | ([SignPostingView, life.qbic.linksmith.spi.WebLinkValidator.IssueReport, Level2LinksetView] as Class[]) |
| 28 | + } |
| 29 | + |
| 30 | + def "stable API: canonical record constructor is available"() { |
| 31 | + when: |
| 32 | + def ctor = SignPostingResult.getDeclaredConstructor( |
| 33 | + SignPostingView, |
| 34 | + life.qbic.linksmith.spi.WebLinkValidator.IssueReport, |
| 35 | + Level2LinksetView |
| 36 | + ) |
| 37 | + |
| 38 | + then: |
| 39 | + ctor != null |
| 40 | + } |
| 41 | + |
| 42 | + def "stable API: record fundamental methods exist"() { |
| 43 | + expect: |
| 44 | + SignPostingResult.getMethod("equals", Object) != null |
| 45 | + SignPostingResult.getMethod("hashCode") != null |
| 46 | + SignPostingResult.getMethod("toString") != null |
| 47 | + } |
| 48 | + |
| 49 | + def "behavior: hasLinkSetView returns false when level2LinksetView is null"() { |
| 50 | + given: |
| 51 | + def view = new SignPostingView([]) |
| 52 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 53 | + |
| 54 | + and: |
| 55 | + def result = new SignPostingResult(view, report, null) |
| 56 | + |
| 57 | + expect: |
| 58 | + !result.hasLinkSetView() |
| 59 | + } |
| 60 | + |
| 61 | + def "behavior: hasLinkSetView returns true when level2LinksetView is present"() { |
| 62 | + given: |
| 63 | + def view = new SignPostingView([]) |
| 64 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 65 | + |
| 66 | + and: |
| 67 | + def nonNullLevel2View = linkSetView() |
| 68 | + |
| 69 | + and: |
| 70 | + def result = new SignPostingResult(view, report, nonNullLevel2View) |
| 71 | + |
| 72 | + expect: |
| 73 | + result.hasLinkSetView() |
| 74 | + } |
| 75 | + |
| 76 | + @Unroll |
| 77 | + def "behavior: hasLinkSetView is consistent with null-check (#caseName)"(String caseName, Level2LinksetView level2View) { |
| 78 | + given: |
| 79 | + def view = new SignPostingView([]) |
| 80 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 81 | + |
| 82 | + and: |
| 83 | + def result = new SignPostingResult(view, report, level2View) |
| 84 | + |
| 85 | + expect: |
| 86 | + result.hasLinkSetView() == (result.level2LinksetView() != null) |
| 87 | + |
| 88 | + where: |
| 89 | + caseName | level2View |
| 90 | + "null view" | null |
| 91 | + "non-null view" | linkSetView() |
| 92 | + } |
| 93 | + |
| 94 | + def "behavior: hasIssues/hasErrors/hasWarnings are all false when IssueReport is empty"() { |
| 95 | + given: |
| 96 | + def view = new SignPostingView([]) |
| 97 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 98 | + |
| 99 | + and: |
| 100 | + def result = new SignPostingResult(view, report, null) |
| 101 | + |
| 102 | + expect: |
| 103 | + !result.hasIssues() |
| 104 | + !result.hasErrors() |
| 105 | + !result.hasWarnings() |
| 106 | + } |
| 107 | + |
| 108 | + def "behavior: hasWarnings true implies hasIssues true (warnings are issues)"() { |
| 109 | + given: |
| 110 | + def view = new SignPostingView([]) |
| 111 | + def warning = life.qbic.linksmith.spi.WebLinkValidator.Issue.warning("w1") |
| 112 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([warning]) |
| 113 | +
|
| 114 | + and: |
| 115 | + def result = new SignPostingResult(view, report, null) |
| 116 | +
|
| 117 | + expect: |
| 118 | + result.hasWarnings() |
| 119 | + !result.hasErrors() |
| 120 | + result.hasIssues() |
| 121 | + } |
| 122 | +
|
| 123 | + def "behavior: hasErrors true implies hasIssues true"() { |
| 124 | + given: |
| 125 | + def view = new SignPostingView([]) |
| 126 | + def error = life.qbic.linksmith.spi.WebLinkValidator.Issue.error("e1") |
| 127 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([error]) |
| 128 | +
|
| 129 | + and: |
| 130 | + def result = new SignPostingResult(view, report, null) |
| 131 | +
|
| 132 | + expect: |
| 133 | + !result.hasWarnings() |
| 134 | + result.hasErrors() |
| 135 | + result.hasIssues() |
| 136 | + } |
| 137 | +
|
| 138 | + def "behavior: withoutLinksetView creates a result with null level2LinksetView"() { |
| 139 | + given: |
| 140 | + def view = new SignPostingView([]) |
| 141 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 142 | +
|
| 143 | + when: |
| 144 | + def result = SignPostingResult.withoutLinksetView(view, report) |
| 145 | +
|
| 146 | + then: |
| 147 | + result.level2LinksetView() == null |
| 148 | + !result.hasLinkSetView() |
| 149 | + } |
| 150 | +
|
| 151 | + def "behavior: withLinksetView rejects null level2LinksetView"() { |
| 152 | + given: |
| 153 | + def view = new SignPostingView([]) |
| 154 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 155 | +
|
| 156 | + when: |
| 157 | + SignPostingResult.withLinksetView(view, report, null) |
| 158 | +
|
| 159 | + then: |
| 160 | + thrown(NullPointerException) |
| 161 | + } |
| 162 | +
|
| 163 | + def "behavior: withLinksetView creates a result with non-null level2LinksetView"() { |
| 164 | + given: |
| 165 | + def view = new SignPostingView([]) |
| 166 | + def report = new life.qbic.linksmith.spi.WebLinkValidator.IssueReport([]) |
| 167 | + def level2 = linkSetView() |
| 168 | +
|
| 169 | + when: |
| 170 | + def result = SignPostingResult.withLinksetView(view, report, level2) |
| 171 | +
|
| 172 | + then: |
| 173 | + result.level2LinksetView().is(level2) |
| 174 | + result.hasLinkSetView() |
| 175 | + } |
| 176 | +
|
| 177 | + private static Level2LinksetView linkSetView() { |
| 178 | + return new Level2LinksetView([], [], [], []) |
| 179 | + } |
| 180 | +} |
0 commit comments