Skip to content

Commit 1262d54

Browse files
committed
Codenarc cleanup. Attempt travis build with JDK7
1 parent 40767f0 commit 1262d54

File tree

11 files changed

+131
-130
lines changed

11 files changed

+131
-130
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: groovy
22
sudo: false
33
jdk:
4-
- oraclejdk8
4+
- oraclejdk7
55
script: ./travis-build.sh
66
before_cache:
77
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

config/codenarc/rules.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ruleset {
2020
DuplicateMapKey
2121
DuplicateSetValue
2222
EmptyCatchBlock
23-
EmptyClass
23+
'EmptyClass' doNotApplyToFilesMatching: '.*Spec.groovy'
2424
EmptyElseBlock
2525
EmptyFinallyBlock
2626
EmptyForStatement
@@ -115,7 +115,7 @@ ruleset {
115115
ToStringReturnsNull
116116

117117
// rulesets/dry.xml
118-
DuplicateListLiteral
118+
'DuplicateListLiteral' doNotApplyToFilesMatching: '.*Spec.groovy'
119119
'DuplicateMapLiteral' doNotApplyToFilesMatching: '.*Spec.groovy'
120120
'DuplicateNumberLiteral' enabled: false
121121
'DuplicateStringLiteral' enabled: false
@@ -154,7 +154,7 @@ ruleset {
154154
BracesForIfElse
155155
BracesForMethod
156156
BracesForTryCatchFinally
157-
ClassJavadoc
157+
'ClassJavadoc' doNotApplyToFilesMatching: '.*Spec.groovy'
158158
ClosureStatementOnOpeningLineOfMultipleLineClosure
159159
ConsecutiveBlankLines
160160
FileEndsWithoutNewline
@@ -308,14 +308,14 @@ ruleset {
308308

309309
// rulesets/size.xml
310310
AbcComplexity // DEPRECATED: Use the AbcMetric rule instead. Requires the GMetrics jar
311-
AbcMetric // Requires the GMetrics jar
311+
'AbcMetric' doNotApplyToFilesMatching: '.*Spec.groovy' // Requires the GMetrics jar
312312
ClassSize
313313
CrapMetric // Requires the GMetrics jar and a Cobertura coverage file
314314
'CyclomaticComplexity' doNotApplyToFilesMatching: '.*Spec.groovy' // Requires the GMetrics jar
315315
MethodCount
316-
MethodSize
317-
'NestedBlockDepth' doNotApplyToFileNames: 'WordDocumentBuilder.groovy'
318-
ParameterCount
316+
'MethodSize' doNotApplyToFilesMatching: '.*Spec.groovy'
317+
NestedBlockDepth
318+
'ParameterCount' maxParameters: 6
319319

320320
// rulesets/unnecessary.xml
321321
AddEmptyString

src/main/groovy/com/jameskleeh/excel/CellStyleBuilder.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class CellStyleBuilder {
216216
new XSSFColor(color)
217217
}
218218

219+
@SuppressWarnings('UnnecessaryGetter')
219220
private BorderStyle getBorderStyle(Object obj) {
220221
if (obj instanceof BorderStyle) {
221222
return (BorderStyle)obj
@@ -240,6 +241,7 @@ class CellStyleBuilder {
240241
}
241242
}
242243

244+
@SuppressWarnings('UnnecessaryGetter')
243245
private void setHorizontalAlignment(XSSFCellStyle cellStyle, Object horizontalAlignment) {
244246
HorizontalAlignment hAlign
245247
if (horizontalAlignment instanceof HorizontalAlignment) {
@@ -255,6 +257,7 @@ class CellStyleBuilder {
255257
}
256258
}
257259

260+
@SuppressWarnings('UnnecessaryGetter')
258261
private void setVerticalAlignment(XSSFCellStyle cellStyle, Object verticalAlignment) {
259262
VerticalAlignment vAlign
260263
if (verticalAlignment instanceof VerticalAlignment) {
@@ -401,7 +404,7 @@ class CellStyleBuilder {
401404
convertSimpleOptions(defaultOptions)
402405
options = merge(defaultOptions, options)
403406
if (!options.containsKey(FORMAT) && value != null) {
404-
def format = Excel.getFormat(value.class)
407+
Object format = Excel.getFormat(value.class)
405408
if (format != null) {
406409
options.put(FORMAT, format)
407410
}

src/main/groovy/com/jameskleeh/excel/Column.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.apache.poi.ss.util.CellRangeAddress
2424
import org.apache.poi.xssf.usermodel.XSSFCell
2525
import org.apache.poi.xssf.usermodel.XSSFRow
2626
import org.apache.poi.xssf.usermodel.XSSFSheet
27-
import org.apache.poi.xssf.usermodel.XSSFWorkbook
2827
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy
2928

3029
/**
@@ -40,7 +39,6 @@ class Column extends CreatesCells {
4039
private int rowIdx
4140

4241
Column(XSSFSheet sheet, Map defaultOptions, Map<Object, Integer> columnIndexes, CellStyleBuilder styleBuilder, int columnIdx, int rowIdx) {
43-
4442
super(sheet, defaultOptions, columnIndexes, styleBuilder)
4543
this.columnIdx = columnIdx
4644
this.rowIdx = rowIdx

src/test/groovy/com/jameskleeh/excel/CellStyleBuilderSpec.groovy

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class CellStyleBuilderSpec extends Specification {
7979
given:
8080
CellStyleBuilder cellStyleBuilder = new CellStyleBuilder(new XSSFWorkbook())
8181
XSSFCellStyle cellStyle
82-
Excel.registerCellFormat(String, "bar")
82+
Excel.registerCellFormat(String, 'bar')
8383

8484
when:
85-
cellStyle = cellStyleBuilder.buildStyle(null, [format: "foo"])
85+
cellStyle = cellStyleBuilder.buildStyle(null, [format: 'foo'])
8686

8787
then:
88-
cellStyle.dataFormatString == "foo"
88+
cellStyle.dataFormatString == 'foo'
8989

9090
when:
9191
cellStyle = cellStyleBuilder.buildStyle(null, [format: 1])
@@ -99,11 +99,11 @@ class CellStyleBuilderSpec extends Specification {
9999
then:
100100
thrown(IllegalArgumentException)
101101

102-
when: "A call to getStyle is essential here to bring in the formats registered in Excel"
103-
cellStyle = cellStyleBuilder.getStyle("someString", [:])
102+
when: 'A call to getStyle is essential here to bring in the formats registered in Excel'
103+
cellStyle = cellStyleBuilder.getStyle('someString', [:])
104104

105105
then:
106-
cellStyle.dataFormatString == "bar"
106+
cellStyle.dataFormatString == 'bar'
107107
}
108108

109109
void "test buildStyle font"() {
@@ -115,7 +115,7 @@ class CellStyleBuilderSpec extends Specification {
115115
cellStyle = cellStyleBuilder.buildStyle('', [font: 1])
116116

117117
then:
118-
def ex = thrown(IllegalArgumentException)
118+
Exception ex = thrown(IllegalArgumentException)
119119
ex.message == 'The font option must be an instance of a Map'
120120

121121
when:
@@ -182,19 +182,19 @@ class CellStyleBuilderSpec extends Specification {
182182
cellStyle = cellStyleBuilder.buildStyle('', [font: [color: 'FFFFFF']])
183183

184184
then:
185-
cellStyle.font.getXSSFColor().getRGB() == [255, 255, 255] as byte[]
185+
cellStyle.font.XSSFColor.RGB == [255, 255, 255] as byte[]
186186

187187
when:
188188
cellStyle = cellStyleBuilder.buildStyle('', [font: [color: '#000000']])
189189

190190
then:
191-
cellStyle.font.getXSSFColor().getRGB() == [0, 0, 0] as byte[]
191+
cellStyle.font.XSSFColor.RGB == [0, 0, 0] as byte[]
192192

193193
when:
194194
cellStyle = cellStyleBuilder.buildStyle('', [font: [color: Color.BLUE]])
195195

196196
then:
197-
cellStyle.font.getXSSFColor().getRGB() == [0, 0, 255] as byte[]
197+
cellStyle.font.XSSFColor.RGB == [0, 0, 255] as byte[]
198198

199199
when:
200200
cellStyle = cellStyleBuilder.buildStyle('', [font: [color: 1L]])
@@ -239,7 +239,7 @@ class CellStyleBuilderSpec extends Specification {
239239
!cellStyle.hidden
240240

241241
when:
242-
cellStyle = cellStyleBuilder.buildStyle('', [hidden: "x"])
242+
cellStyle = cellStyleBuilder.buildStyle('', [hidden: 'x'])
243243

244244
then:
245245
thrown(IllegalArgumentException)
@@ -263,7 +263,7 @@ class CellStyleBuilderSpec extends Specification {
263263
!cellStyle.locked
264264

265265
when:
266-
cellStyle = cellStyleBuilder.buildStyle('', [locked: "x"])
266+
cellStyle = cellStyleBuilder.buildStyle('', [locked: 'x'])
267267

268268
then:
269269
thrown(IllegalArgumentException)
@@ -287,7 +287,7 @@ class CellStyleBuilderSpec extends Specification {
287287
!cellStyle.wrapText
288288

289289
when:
290-
cellStyle = cellStyleBuilder.buildStyle('', [wrapped: "x"])
290+
cellStyle = cellStyleBuilder.buildStyle('', [wrapped: 'x'])
291291

292292
then:
293293
thrown(IllegalArgumentException)
@@ -371,7 +371,7 @@ class CellStyleBuilderSpec extends Specification {
371371
cellStyle.rotation == (short)1
372372

373373
when:
374-
cellStyle = cellStyleBuilder.buildStyle('', [rotation: "foo"])
374+
cellStyle = cellStyleBuilder.buildStyle('', [rotation: 'foo'])
375375

376376
then:
377377
thrown(ClassCastException)
@@ -395,7 +395,7 @@ class CellStyleBuilderSpec extends Specification {
395395
cellStyle.indention == (short)1
396396

397397
when:
398-
cellStyle = cellStyleBuilder.buildStyle('', [indent: "foo"])
398+
cellStyle = cellStyleBuilder.buildStyle('', [indent: 'foo'])
399399

400400
then:
401401
thrown(ClassCastException)
@@ -414,30 +414,30 @@ class CellStyleBuilderSpec extends Specification {
414414

415415
when:
416416
cellStyle = cellStyleBuilder.buildStyle('', [border: [style: BorderStyle.DOTTED, color: Color.RED]])
417+
byte[] color = [255, 0, 0] as byte[]
417418

418419
then:
419420
cellStyle.borderLeftEnum == BorderStyle.DOTTED
420-
cellStyle.leftBorderXSSFColor.getRGB() == [255, 0, 0] as byte[]
421+
cellStyle.leftBorderXSSFColor.RGB == color
421422
cellStyle.borderRightEnum == BorderStyle.DOTTED
422-
cellStyle.rightBorderXSSFColor.getRGB() == [255, 0, 0] as byte[]
423+
cellStyle.rightBorderXSSFColor.RGB == color
423424
cellStyle.borderBottomEnum == BorderStyle.DOTTED
424-
cellStyle.bottomBorderXSSFColor.getRGB() == [255, 0, 0] as byte[]
425+
cellStyle.bottomBorderXSSFColor.RGB == color
425426
cellStyle.borderTopEnum == BorderStyle.DOTTED
426-
cellStyle.topBorderXSSFColor.getRGB() == [255, 0, 0] as byte[]
427+
cellStyle.topBorderXSSFColor.RGB == color
427428

428429
when:
429-
cellStyle = cellStyleBuilder.buildStyle('', [border: [style: BorderStyle.DOTTED, color: Color.RED, left: [color: Color.BLUE], right: [style: BorderStyle.DASHED], bottom: [color: "FFFFFF"], top: [color: "#000000"]]])
430+
cellStyle = cellStyleBuilder.buildStyle('', [border: [style: BorderStyle.DOTTED, color: Color.RED, left: [color: Color.BLUE], right: [style: BorderStyle.DASHED], bottom: [color: 'FFFFFF'], top: [color: '#000000']]])
430431

431432
then:
432433
cellStyle.borderLeftEnum == BorderStyle.DOTTED
433-
cellStyle.leftBorderXSSFColor.getRGB() == [0, 0, 255] as byte[]
434+
cellStyle.leftBorderXSSFColor.RGB == [0, 0, 255] as byte[]
434435
cellStyle.borderRightEnum == BorderStyle.DASHED
435-
cellStyle.rightBorderXSSFColor.getRGB() == [255, 0, 0] as byte[]
436+
cellStyle.rightBorderXSSFColor.RGB == [255, 0, 0] as byte[]
436437
cellStyle.borderBottomEnum == BorderStyle.DOTTED
437-
cellStyle.bottomBorderXSSFColor.getRGB() == [255, 255, 255] as byte[]
438+
cellStyle.bottomBorderXSSFColor.RGB == [255, 255, 255] as byte[]
438439
cellStyle.borderTopEnum == BorderStyle.DOTTED
439-
cellStyle.topBorderXSSFColor.getRGB() == [0, 0, 0] as byte[]
440-
440+
cellStyle.topBorderXSSFColor.RGB == [0, 0, 0] as byte[]
441441

442442
when:
443443
Map options = [border: [style: BorderStyle.DOTTED, left: BorderStyle.THIN]]
@@ -469,13 +469,13 @@ class CellStyleBuilderSpec extends Specification {
469469
cellStyle.fillPatternEnum == FillPatternType.DIAMONDS
470470

471471
when:
472-
cellStyle = cellStyleBuilder.buildStyle('', [fill: "diamonds"])
472+
cellStyle = cellStyleBuilder.buildStyle('', [fill: 'diamonds'])
473473

474474
then:
475475
cellStyle.fillPatternEnum == FillPatternType.DIAMONDS
476476

477477
when:
478-
cellStyle = cellStyleBuilder.buildStyle('', [fill: "x"])
478+
cellStyle = cellStyleBuilder.buildStyle('', [fill: 'x'])
479479

480480
then:
481481
thrown(IllegalArgumentException)
@@ -496,22 +496,22 @@ class CellStyleBuilderSpec extends Specification {
496496
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: Color.RED])
497497

498498
then:
499-
cellStyle.fillForegroundXSSFColor.getRGB() == [255, 0, 0] as byte[]
499+
cellStyle.fillForegroundXSSFColor.RGB == [255, 0, 0] as byte[]
500500

501501
when:
502-
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: "FFFFFF"])
502+
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: 'FFFFFF'])
503503

504504
then:
505-
cellStyle.fillForegroundXSSFColor.getRGB() == [255, 255, 255] as byte[]
505+
cellStyle.fillForegroundXSSFColor.RGB == [255, 255, 255] as byte[]
506506

507507
when:
508-
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: "#000000"])
508+
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: '#000000'])
509509

510510
then:
511-
cellStyle.fillForegroundXSSFColor.getRGB() == [0, 0, 0] as byte[]
511+
cellStyle.fillForegroundXSSFColor.RGB == [0, 0, 0] as byte[]
512512

513513
when:
514-
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: "blue"])
514+
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: 'blue'])
515515

516516
then:
517517
thrown(IllegalArgumentException)
@@ -522,35 +522,35 @@ class CellStyleBuilderSpec extends Specification {
522522
CellStyleBuilder cellStyleBuilder = new CellStyleBuilder(new XSSFWorkbook())
523523
XSSFCellStyle cellStyle
524524

525-
when: "Only the background color is specified"
525+
when: 'Only the background color is specified'
526526
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: Color.RED])
527527

528-
then: "The foreground color is set instead of the background and the fill pattern is set to solid"
529-
cellStyle.fillForegroundXSSFColor.getRGB() == [255, 0, 0] as byte[]
528+
then: 'The foreground color is set instead of the background and the fill pattern is set to solid'
529+
cellStyle.fillForegroundXSSFColor.RGB == [255, 0, 0] as byte[]
530530
cellStyle.fillBackgroundXSSFColor == null
531531
cellStyle.fillPatternEnum == FillPatternType.SOLID_FOREGROUND
532532

533-
when: "Both the foreground and background colors are specified"
533+
when: 'Both the foreground and background colors are specified'
534534
cellStyle = cellStyleBuilder.buildStyle('', [foregroundColor: Color.BLUE, backgroundColor: Color.RED])
535535

536-
then: "Both are set"
537-
cellStyle.fillForegroundXSSFColor.getRGB() == [0, 0, 255] as byte[]
538-
cellStyle.fillBackgroundXSSFColor.getRGB() == [255, 0, 0] as byte[]
536+
then: 'Both are set'
537+
cellStyle.fillForegroundXSSFColor.RGB == [0, 0, 255] as byte[]
538+
cellStyle.fillBackgroundXSSFColor.RGB == [255, 0, 0] as byte[]
539539

540540
when:
541-
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: "FFFFFF"])
541+
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: 'FFFFFF'])
542542

543543
then:
544-
cellStyle.fillForegroundXSSFColor.getRGB() == [255, 255, 255] as byte[]
544+
cellStyle.fillForegroundXSSFColor.RGB == [255, 255, 255] as byte[]
545545

546546
when:
547-
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: "#000000"])
547+
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: '#000000'])
548548

549549
then:
550-
cellStyle.fillForegroundXSSFColor.getRGB() == [0, 0, 0] as byte[]
550+
cellStyle.fillForegroundXSSFColor.RGB == [0, 0, 0] as byte[]
551551

552552
when:
553-
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: "blue"])
553+
cellStyle = cellStyleBuilder.buildStyle('', [backgroundColor: 'blue'])
554554

555555
then:
556556
thrown(IllegalArgumentException)
@@ -583,7 +583,6 @@ class CellStyleBuilderSpec extends Specification {
583583
cell.cellStyle == defaultCell.cellStyle
584584
}
585585

586-
587586
void "test setStyle cell options"() {
588587
given:
589588
XSSFWorkbook workbook = new XSSFWorkbook()

0 commit comments

Comments
 (0)