package com.openxc.messages;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import android.os.Parcel;

@Config(emulateSdk = 18, manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class SimpleVehicleMessageTest {
    SimpleVehicleMessage message;
    Double value = Double.valueOf(42);
    String name = "foo";

    @Before
    public void setup() {
        message = new SimpleVehicleMessage(name, value);
    }

    @Test
    public void getNameReturnsName() {
        assertEquals(name, message.getName());
    }

    @Test
    public void sameEquals() {
        assertEquals(message, message);
    }

    @Test
    public void sameNameAndValueEquals() {
        SimpleVehicleMessage anotherMessage = new SimpleVehicleMessage(
                message.getTimestamp(), name, value);
        assertEquals(message, anotherMessage);
    }

    @Test
    public void differentValueDoesntEqual() {
        NamedVehicleMessage anotherMessage = new SimpleVehicleMessage(
                name, Double.valueOf(24));
        assertFalse(message.equals(anotherMessage));
    }

    @Test
    public void toStringNotNull() {
        assertThat(message.toString(), notNullValue());
    }

    @Test
    public void writeAndReadFromParcel() {
        Parcel parcel = Parcel.obtain();
        message.writeToParcel(parcel, 0);

        // Reset parcel for reading
        parcel.setDataPosition(0);

        VehicleMessage createdFromParcel =
                VehicleMessage.CREATOR.createFromParcel(parcel);
        assertThat(createdFromParcel, instanceOf(SimpleVehicleMessage.class));
        assertEquals(message, createdFromParcel);
    }

    @Test
    public void keyNotNull() {
        assertThat(message.getKey(), notNullValue());
    }
}

@@ -913,32 +913,487 @@
 essage);%0A    %7D%0A%0A
+    @Test%0A    public void valueAsNumber() %7B%0A        assertEquals(message.getValueAsNumber(), value);%0A    %7D%0A%0A    @Test%0A    public void valueAsString() %7B%0A        message = new SimpleVehicleMessage(name, %22foo%22);%0A        assertEquals(message.getValueAsString(), %22foo%22);%0A    %7D%0A%0A    @Test%0A    public void valueAsBoolean() %7B%0A        message = new SimpleVehicleMessage(name, Boolean.valueOf(true));%0A        assertEquals(message.getValueAsBoolean(), true);%0A    %7D%0A%0A
     @Test%0A    pu

Test converting simple value to different types.