Last active
February 9, 2026 08:31
-
-
Save trikitrok/099f892f67224ebd6f65f9f9b7a2c0c5 to your computer and use it in GitHub Desktop.
Revisions
-
trikitrok revised this gist
Feb 9, 2026 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -94,7 +94,7 @@ public AlarmForTesting(Double... values) { } @Override protected void notify(String message) { shownMessages.add(message); } -
trikitrok revised this gist
Feb 6, 2026 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -65,7 +65,7 @@ private void checkNoMessagesWereShown() { } private void checkShownMessagesWere(String... expectedMessages) { assertThat(alarm.shownMessages).isEqualTo(Arrays.asList(expectedMessages)); } private AlarmForTesting aDeactivatedAfterActivationAlarmSampling(double sampledValue) { -
trikitrok created this gist
Feb 6, 2026 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,107 @@ package unit_tests; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import tirepressuremonitoringsystem.Alarm; import java.util.*; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; class AlarmTest { private AlarmForTesting alarm; @Test void alarm_activates_when_sampled_pressure_is_too_low() { alarm = alarmSampling(16.99); alarm.check(); checkShownMessagesWere("Alarm activated!"); } @ParameterizedTest @ValueSource(doubles = {17.00, 21.00}) void alarm_does_not_activate_when_sampled_pressure_is_safe(double sampledPressure) { alarm = alarmSampling(sampledPressure); alarm.check(); checkNoMessagesWereShown(); } @Test void alarm_activates_when_sampled_pressure_is_too_high() { alarm = alarmSampling(21.01); alarm.check(); checkShownMessagesWere("Alarm activated!"); } @Test void activated_alarm_does_not_notify_activation_again_when_sampled_pressure_is_not_safe() { alarm = anActivatedAlarmSampling(25.0); alarm.check(); checkShownMessagesWere("Alarm activated!"); } @Test public void deactivated_alarm_after_activation_activates_when_sampled_pressure_is_not_safe() { alarm = aDeactivatedAfterActivationAlarmSampling(50.0); alarm.check(); checkShownMessagesWere("Alarm activated!", "Alarm deactivated!", "Alarm activated!"); } private void checkNoMessagesWereShown() { checkShownMessagesWere(); } private void checkShownMessagesWere(String... expectedMessages) { assertThat(this.alarm.shownMessages).isEqualTo(Arrays.asList(expectedMessages)); } private AlarmForTesting aDeactivatedAfterActivationAlarmSampling(double sampledValue) { var alarm = anActivatedAlarmSampling(18.00, sampledValue); alarm.check(); return alarm; } private AlarmForTesting anActivatedAlarmSampling(Double... sampledValues) { var alarm = alarmSampling(Stream.concat(Stream.of(200.00), Arrays.stream(sampledValues)).toArray(Double[]::new)); alarm.check(); return alarm; } private AlarmForTesting alarmSampling(Double... values) { return new AlarmForTesting(values); } static class AlarmForTesting extends Alarm { private final Queue<Double> sampledValues; public List<String> shownMessages; public AlarmForTesting(Double... values) { this.shownMessages = new ArrayList<>(); this.sampledValues = new ArrayDeque<>(Arrays.asList(values)); } @Override protected void showMessage(String message) { shownMessages.add(message); } @Override protected double sampleValue() { return sampledValues.remove(); } } }