desislava_topuzakova

6. Tire Pressure Monitoring System

Nov 26th, 2020
821
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package p06_TirePressureMonitoringSystem;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import org.mockito.Mockito;
  6.  
  7. public class AlarmTest {
  8.  
  9.     //1. налагяне по минимум < 17 -> on (true)
  10.     //2. налагяне над макс > 21 -> оn (true)
  11.     //3. ако е нормално налягането (между 17 и 21)-> оff (false)
  12.  
  13.     @Test
  14.     public void testAlarmWithLowerValue() {
  15.         Sensor sensor = Mockito.mock(Sensor.class);
  16.         Mockito.when(sensor.popNextPressurePsiValue()).thenReturn(16.9);
  17.         Alarm alarm = new Alarm(sensor);
  18.         alarm.check();
  19.         Assert.assertTrue(alarm.getAlarmOn());
  20.     }
  21.  
  22.     @Test
  23.     public void testAlarmWithHigherValue() {
  24.         Sensor sensor = Mockito.mock(Sensor.class);
  25.         Mockito.when(sensor.popNextPressurePsiValue()).thenReturn(22.5);
  26.         Alarm alarm = new Alarm(sensor);
  27.         alarm.check();
  28.         Assert.assertTrue(alarm.getAlarmOn());
  29.     }
  30.  
  31.     @Test
  32.     public void testAlarmWithNormalValue() {
  33.         Sensor sensor = Mockito.mock(Sensor.class);
  34.         Mockito.when(sensor.popNextPressurePsiValue()).thenReturn(18.4);
  35.         Alarm alarm = new Alarm(sensor);
  36.         alarm.check();
  37.         Assert.assertFalse(alarm.getAlarmOn());
  38.     }
  39. }
  40.  
RAW Paste Data