Skip to content

Commit 5271d07

Browse files
authored
Merge pull request #207 from ie3-institute/ck/#206-fixTests
Fix tests in CI
2 parents 9da3a3a + 02a345c commit 5271d07

File tree

8 files changed

+58
-7
lines changed

8 files changed

+58
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased/Snapshot]
8+
### Fixed
9+
- Fix tests in CI [#206](https://github.com/ie3-institute/PowerSystemUtils/issues/206)
10+
- Enable using JUnit platform
11+
- Fix broken tests
12+
- Let scalatest and JUnit tests run together
813

914
## [1.6.0]
1015

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ apply from: scriptsLocation + 'pmd.gradle'
2929
apply from: scriptsLocation + 'spotbugs.gradle'
3030
apply from: scriptsLocation + 'spotless.gradle'
3131
apply from: scriptsLocation + 'checkJavaVersion.gradle'
32+
apply from: scriptsLocation + 'test.gradle'
3233
apply from: scriptsLocation + 'jacoco.gradle' // jacoco java code coverage
3334
apply from: scriptsLocation + 'mavenCentralPublish.gradle'
3435
apply from: scriptsLocation + 'sonarqube.gradle'

gradle/scripts/sonarqube.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sonarqube {
1515
'src/test/groovy'] // test src dirs
1616
// reports stuff (for all languages)
1717
property 'sonar.junit.reportPaths', [
18-
'build/test-results/allTests'] // Comma-delimited list of paths to Surefire XML-format reports.
18+
'build/test-results/test'] // Comma-delimited list of paths to Surefire XML-format reports.
1919
// unit tests reports dirs
2020
property "sonar.coverage.jacoco.xmlReportsPath", [
2121
"build/reports/jacoco/test/jacocoTestReport.xml"] // Comma-separated list of paths to JaCoCo (jacoco.xml) report files.

gradle/scripts/spotless.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ spotless {
3838

3939
// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
4040
format 'misc', {
41-
target '**/*.gradle', '**/*.md', '**/.gitignore', 'configs/**'
41+
target '**/*.gradle', '**/.gitignore', 'configs/**'
4242
trimTrailingWhitespace()
4343
indentWithTabs()
4444
endWithNewline()
4545
}
46+
47+
format 'markdown', {
48+
target '**/*.md'
49+
indentWithSpaces(2)
50+
endWithNewline()
51+
}
4652
}

gradle/scripts/test.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//Configure test reporting
2+
test {
3+
useJUnitPlatform()
4+
testLogging {
5+
events "skipped", "failed"
6+
}
7+
8+
dependsOn scalatest
9+
}

src/main/java/edu/ie3/util/quantities/EmptyQuantity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public Quantity<Q> negate() {
176176
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
177177
}
178178

179+
@Override
180+
public int compareTo(Quantity<Q> that) {
181+
if (that.getClass().isAssignableFrom(EmptyQuantity.class)) return 0;
182+
else
183+
throw new EmptyQuantityException(
184+
"An empty quantity cannot be compared against an actual quantity (" + that + ").");
185+
}
186+
179187
/**
180188
* Decides equality based <b>only</b> on the type of the object: If it is an EmptyQuantity, it is
181189
* equal. This is based on the thought that nothing is always equals to nothing.

src/test/groovy/edu/ie3/util/io/FileIOUtilsTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FileIOUtilsTest extends Specification {
9090
then:
9191
noExceptionThrown()
9292
Files.exists(archiveFile)
93-
Files.size(archiveFile) >= 1330 && Files.size(archiveFile) <= 1412 // Should be around 1371 bytes +/- 3 %
93+
Files.size(archiveFile) >= 1317 && Files.size(archiveFile) <= 1399 // Should be around 1385 bytes +/- 3 %
9494
}
9595

9696
def "The fileio utils is able to zip the contents of a directory with nested structure to .tar.gz"() {
@@ -105,7 +105,7 @@ class FileIOUtilsTest extends Specification {
105105
then:
106106
noExceptionThrown()
107107
Files.exists(archiveFile)
108-
Files.size(archiveFile) >= 1370 && Files.size(archiveFile) <= 1454 // Should be around 1412 bytes +/- 3 %
108+
Files.size(archiveFile) >= 1384 && Files.size(archiveFile) <= 1427 // Should be around 1427 bytes +/- 3 %
109109
}
110110

111111
def "The fileio utils throws an exception, if the input path is null when called to compress a file"() {
@@ -437,6 +437,6 @@ class FileIOUtilsTest extends Specification {
437437
tmpDirectory.toString() + "/extract/line_input.csv"
438438
]
439439
/* Check unzipped file size */
440-
unzippedFile.size() == testFile.size()
440+
Files.size(unzippedFile) == Files.size(testFile)
441441
}
442442
}

src/test/groovy/edu/ie3/util/quantities/EmptyQuantityTest.groovy

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,36 @@ class EmptyQuantityTest extends Specification {
2626
EmptyQuantity.of(PowerSystemUnits.WATT) || PowerSystemUnits.WATT
2727
}
2828

29+
def "EmptyQuantity is not equal to a regular Quantity "() {
30+
when:
31+
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
32+
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)
33+
34+
nullMetreQuantity.compareTo(filledMetreQuantity)
35+
36+
then:
37+
def thrown = thrown(EmptyQuantityException)
38+
thrown.message == "An empty quantity cannot be compared against an actual quantity (17.1 m)."
39+
}
40+
41+
def "regular Quantity is not equal to a regular Quantity EmptyQuantity"() {
42+
when:
43+
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
44+
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)
45+
46+
filledMetreQuantity.compareTo(nullMetreQuantity)
47+
48+
then:
49+
def thrown = thrown(NullPointerException)
50+
thrown.message == "Cannot invoke \"Object.getClass()\" because \"number\" is null"
51+
}
52+
2953
def "EmptyQuantity is never equivalent or equal to a regular Quantity "() {
3054
when:
3155
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
3256
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)
3357

3458
then:
35-
nullMetreQuantity != filledMetreQuantity
36-
filledMetreQuantity != nullMetreQuantity
3759
!nullMetreQuantity.isEquivalentTo(filledMetreQuantity)
3860
}
3961

0 commit comments

Comments
 (0)