-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: metadata now defines which components are used to compute total
- Loading branch information
Showing
11 changed files
with
214 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
metadata/src/test/java/net/laprun/sustainability/power/SensorMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.laprun.sustainability.power; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class SensorMetadataTest { | ||
@Test | ||
void shouldFailIfTotalComponentsAreOutOfRange() { | ||
final var e = assertThrows(IllegalArgumentException.class, | ||
() -> new SensorMetadata(Collections.emptyMap(), "", new int[] { 0, 1, -1 })); | ||
final var message = e.getMessage(); | ||
assertTrue(message.contains("0")); | ||
assertTrue(message.contains("1")); | ||
assertTrue(message.contains("-1")); | ||
} | ||
|
||
@Test | ||
void shouldFailIfTotalComponentsAreNotCommensurateToWatts() { | ||
final var e = assertThrows(IllegalArgumentException.class, | ||
() -> new SensorMetadata( | ||
Map.of("foo", new SensorMetadata.ComponentMetadata("foo", 0, "", false, SensorUnit.decimalPercentage)), | ||
"", new int[] { 0, 1, -1 })); | ||
final var message = e.getMessage(); | ||
assertTrue(message.contains("1")); | ||
assertTrue(message.contains("-1")); | ||
assertTrue(message.contains("foo")); | ||
} | ||
|
||
@Test | ||
void shouldFailIfNoTotalComponentsAreProvided() { | ||
final var e = assertThrows(NullPointerException.class, | ||
() -> new SensorMetadata(Collections.emptyMap(), "", null)); | ||
final var message = e.getMessage(); | ||
assertTrue(message.contains("Must provide total components")); | ||
} | ||
|
||
@Test | ||
void shouldFailIfNoComponentsAreProvided() { | ||
final var e = assertThrows(NullPointerException.class, | ||
() -> new SensorMetadata(null, "", null)); | ||
final var message = e.getMessage(); | ||
assertTrue(message.contains("Must provide components")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.