public DiagnosticResponse(int busId, int id, int mode, int pid, byte[] payload) { super(busId, id, mode, pid); setPayload(payload); }
@Test public void differentIdNotEqual() { DiagnosticResponse anotherResponse = new DiagnosticResponse( bus, id + 1, mode, pid, payload); anotherResponse.setPayload(payload); assertThat(response, not(equalTo(anotherResponse))); }
@Test public void differentBusNotEqual() { DiagnosticResponse anotherResponse = new DiagnosticResponse( bus + 1, id, mode, pid, payload); anotherResponse.setPayload(payload); assertThat(response, not(equalTo(anotherResponse))); }
@Test public void differentPayloadNotEqual() { payload[1] = (byte) (payload[1] + 1); DiagnosticResponse anotherResponse = new DiagnosticResponse( bus, id, mode, pid, payload); anotherResponse.setPayload(payload); assertThat(response, not(equalTo(anotherResponse))); }
@Test public void differentModeNotEqual() { DiagnosticResponse anotherResponse = new DiagnosticResponse( bus, id, mode + 1, pid, payload); anotherResponse.setPayload(payload); assertThat(response, not(equalTo(anotherResponse))); }
@Test public void clearPayload() { response.setPayload(null); assertThat(response.getPayload(), nullValue()); }
@Test public void parcelWithNoPayload() { response.setPayload(null); Parcel parcel = Parcel.obtain(); response.writeToParcel(parcel, 0); // Reset parcel for reading parcel.setDataPosition(0); VehicleMessage createdFromParcel = VehicleMessage.CREATOR.createFromParcel(parcel); assertThat(createdFromParcel, instanceOf(DiagnosticResponse.class)); assertEquals(response, createdFromParcel); assertThat(response.getPayload(), nullValue()); }
private static DiagnosticResponse deserializeDiagnosticResponse( BinaryMessages.VehicleMessage binaryMessage) throws UnrecognizedMessageTypeException { BinaryMessages.DiagnosticResponse serializedResponse = binaryMessage.getDiagnosticResponse(); if(!serializedResponse.hasBus() || !serializedResponse.hasMessageId() || !serializedResponse.hasMode()) { throw new UnrecognizedMessageTypeException( "Diagnostic response missing one or more required fields"); } DiagnosticResponse response = new DiagnosticResponse( serializedResponse.getBus(), serializedResponse.getMessageId(), serializedResponse.getMode()); if(serializedResponse.hasPid()) { response.setPid(serializedResponse.getPid()); } if(serializedResponse.hasPayload()) { response.setPayload(serializedResponse.getPayload().toByteArray()); } if(serializedResponse.hasNegativeResponseCode()) { response.setNegativeResponseCode( DiagnosticResponse.NegativeResponseCode.get( serializedResponse.getNegativeResponseCode())); } if(serializedResponse.hasValue()) { response.setValue(serializedResponse.getValue()); } return response; }