Example #1
0
  /**
   * Test for valid InputStream read
   *
   * @throws IOException
   */
  @Test
  public void testHighRPM() throws IOException {
    // mock InputStream read
    mockIn = createMock(InputStream.class);
    mockIn.read();
    expectLastCall().andReturn((byte) '4');
    expectLastCall().andReturn((byte) '1');
    expectLastCall().andReturn((byte) ' ');
    expectLastCall().andReturn((byte) '0');
    expectLastCall().andReturn((byte) 'C');
    expectLastCall().andReturn((byte) ' ');
    expectLastCall().andReturn((byte) '2');
    expectLastCall().andReturn((byte) '8');
    expectLastCall().andReturn((byte) ' ');
    expectLastCall().andReturn((byte) '3');
    expectLastCall().andReturn((byte) 'C');
    expectLastCall().andReturn((byte) '>');

    replayAll();

    // call the method to test
    command.readResult(mockIn);
    assertEquals(command.getRPM(), 2575);

    verifyAll();
  }
  private void updateTripStatistic(final ObdCommandJob job, final String cmdID) {

    if (currentTrip != null) {
      if (cmdID.equals(AvailableCommandNames.SPEED.toString())) {
        SpeedCommand command = (SpeedCommand) job.getCommand();
        currentTrip.setSpeedMax(command.getMetricSpeed());
      } else if (cmdID.equals(AvailableCommandNames.ENGINE_RPM.toString())) {
        RPMCommand command = (RPMCommand) job.getCommand();
        currentTrip.setEngineRpmMax(command.getRPM());
      } else if (cmdID.endsWith(AvailableCommandNames.ENGINE_RUNTIME.toString())) {
        RuntimeCommand command = (RuntimeCommand) job.getCommand();
        currentTrip.setEngineRuntime(command.getFormattedResult());
      }
    }
  }