Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

## [1.6.0]

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ apply from: scriptsLocation + 'pmd.gradle'
apply from: scriptsLocation + 'spotbugs.gradle'
apply from: scriptsLocation + 'spotless.gradle'
apply from: scriptsLocation + 'checkJavaVersion.gradle'
apply from: scriptsLocation + 'test.gradle'
apply from: scriptsLocation + 'jacoco.gradle' // jacoco java code coverage
apply from: scriptsLocation + 'mavenCentralPublish.gradle'
apply from: scriptsLocation + 'sonarqube.gradle'
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/sonarqube.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sonarqube {
'src/test/groovy'] // test src dirs
// reports stuff (for all languages)
property 'sonar.junit.reportPaths', [
'build/test-results/allTests'] // Comma-delimited list of paths to Surefire XML-format reports.
'build/test-results/test'] // Comma-delimited list of paths to Surefire XML-format reports.
// unit tests reports dirs
property "sonar.coverage.jacoco.xmlReportsPath", [
"build/reports/jacoco/test/jacocoTestReport.xml"] // Comma-separated list of paths to JaCoCo (jacoco.xml) report files.
Expand Down
8 changes: 7 additions & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ spotless {

// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore', 'configs/**'
target '**/*.gradle', '**/.gitignore', 'configs/**'
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}

format 'markdown', {
target '**/*.md'
indentWithSpaces(2)
endWithNewline()
}
}
9 changes: 9 additions & 0 deletions gradle/scripts/test.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//Configure test reporting
test {
useJUnitPlatform()
testLogging {
events "skipped", "failed"
}

dependsOn scalatest
}
8 changes: 8 additions & 0 deletions src/main/java/edu/ie3/util/quantities/EmptyQuantity.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public Quantity<Q> negate() {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}

@Override
public int compareTo(Quantity<Q> that) {
if (that.getClass().isAssignableFrom(EmptyQuantity.class)) return 0;
else
throw new EmptyQuantityException(
"An empty quantity cannot be compared against an actual quantity (" + that + ").");
}

/**
* Decides equality based <b>only</b> on the type of the object: If it is an EmptyQuantity, it is
* equal. This is based on the thought that nothing is always equals to nothing.
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/edu/ie3/util/io/FileIOUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FileIOUtilsTest extends Specification {
then:
noExceptionThrown()
Files.exists(archiveFile)
Files.size(archiveFile) >= 1330 && Files.size(archiveFile) <= 1412 // Should be around 1371 bytes +/- 3 %
Files.size(archiveFile) >= 1317 && Files.size(archiveFile) <= 1399 // Should be around 1385 bytes +/- 3 %
}

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

def "The fileio utils throws an exception, if the input path is null when called to compress a file"() {
Expand Down Expand Up @@ -437,6 +437,6 @@ class FileIOUtilsTest extends Specification {
tmpDirectory.toString() + "/extract/line_input.csv"
]
/* Check unzipped file size */
unzippedFile.size() == testFile.size()
Files.size(unzippedFile) == Files.size(testFile)
}
}
26 changes: 24 additions & 2 deletions src/test/groovy/edu/ie3/util/quantities/EmptyQuantityTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,36 @@ class EmptyQuantityTest extends Specification {
EmptyQuantity.of(PowerSystemUnits.WATT) || PowerSystemUnits.WATT
}

def "EmptyQuantity is not equal to a regular Quantity "() {
when:
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)

nullMetreQuantity.compareTo(filledMetreQuantity)

then:
def thrown = thrown(EmptyQuantityException)
thrown.message == "An empty quantity cannot be compared against an actual quantity (17.1 m)."
}

def "regular Quantity is not equal to a regular Quantity EmptyQuantity"() {
when:
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)

filledMetreQuantity.compareTo(nullMetreQuantity)

then:
def thrown = thrown(NullPointerException)
thrown.message == "Cannot invoke \"Object.getClass()\" because \"number\" is null"
}

def "EmptyQuantity is never equivalent or equal to a regular Quantity "() {
when:
def nullMetreQuantity = EmptyQuantity.of(PowerSystemUnits.METRE)
def filledMetreQuantity = Quantities.getQuantity(17.1, PowerSystemUnits.METRE)

then:
nullMetreQuantity != filledMetreQuantity
filledMetreQuantity != nullMetreQuantity
!nullMetreQuantity.isEquivalentTo(filledMetreQuantity)
}

Expand Down