@Before public void setup() { message = new Command(command); }
switch (selectedItem) { case VERSION_POS: request = new Command(Command.CommandType.VERSION); break; request = new Command(Command.CommandType.DEVICE_ID); break; request = new Command(Command.CommandType.PLATFORM); break; enabled = Boolean.valueOf( mEnabledSpinner.getSelectedItem().toString()); request = new Command( Command.CommandType.PASSTHROUGH, selectedBus, enabled); break; bypass = Boolean.valueOf( mBypassSpinner.getSelectedItem().toString()); request = new Command(Command.CommandType.AF_BYPASS, bypass, selectedBus); break; request = new Command(format, Command.CommandType.PAYLOAD_FORMAT); break; request = new Command(Command.CommandType.RTC_CONFIGURATION, new Date().getTime()/1000L); break; request = new Command(Command.CommandType.SD_MOUNT_STATUS);
@Test public void serializeCommandUsesStringCommand() { String serialized = JsonFormatter.serialize(new Command( Command.CommandType.VERSION)); assertThat(serialized, containsString("version")); }
if(message instanceof DiagnosticRequest) { wrappedMessage = new Command(message.asDiagnosticRequest(), DiagnosticRequest.ADD_ACTION_KEY);
/** * Send a command request to the vehicle that does not require any metadata. * * @param type The command request type to send to the VI. * @return The message returned by the VI in response to this command or * null if none was received. */ public String requestCommandMessage(CommandType type) { VehicleMessage message = request(new Command(type)); String value = null; if(message != null) { // Because we use the same key and value for commands and command // responses, if for some reason a Command is echoed back to the // device instead of a CommandResponse, you could get a casting // exception when trying to cast this message here. If we got a // Command, just ignore it and assume no response - I wasn't able to // reproduce it but we did have a few Bugsnag reports about it. try { CommandResponse response = message.asCommandResponse(); if(response.getStatus()) { value = response.getMessage(); } } catch(ClassCastException e) { Log.w(TAG, "Expected a command response but got " + message + " -- ignoring, assuming no response"); } } return value; }
@Test public void serializeCommand() { serializeDeserializeAndCheckEqual(new Command( Command.CommandType.VERSION)); }
@Test public void sameCommandEquals() { Command anotherMessage = new Command(command); assertEquals(message, anotherMessage); }
@Test public void serializeCommandWithDiagnosticRequest() { DiagnosticRequest request = new DiagnosticRequest(1, 2, 3, 4); serializeDeserializeAndCheckEqual(new Command(request, "add")); }
@Test public void serializeCommandWithDiagnosticRequestNoPid() { DiagnosticRequest request = new DiagnosticRequest(1, 2, 3); serializeDeserializeAndCheckEqual(new Command(request, "add")); }
@Test public void writeAndReadFromParcelWithDiagnostic() { message = new Command(request, action); Parcel parcel = Parcel.obtain(); message.writeToParcel(parcel, 0); // Reset parcel for reading parcel.setDataPosition(0); VehicleMessage createdFromParcel = VehicleMessage.CREATOR.createFromParcel(parcel); assertThat(createdFromParcel, instanceOf(Command.class)); assertEquals(message, createdFromParcel); }
@Test public void matchesKeyFromCommand() { Command originalCommand = new Command(command); KeyMatcher matcher = ExactKeyMatcher.buildExactMatcher(originalCommand); assertTrue(matcher.matches(response)); } }
@Test public void serializeDiagnosticRequestWithOptional() { DiagnosticRequest request = new DiagnosticRequest(1, 2, 3, 4); request.setPayload(new byte[]{1,2,3,4}); request.setMultipleResponses(false); request.setFrequency(2.0); request.setName("foo"); serializeDeserializeAndCheckEqual(new Command(request, "add")); }
deserializedCommand = deserializeDiagnosticCommand(command); } else { deserializedCommand = new Command(commandType);
request.setName(serializedRequest.getName()); return new Command(request, action);