/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.android.apps.mytracks.services.sensors.ant;

import com.google.android.apps.mytracks.services.sensors.ant.AntSensorManager;

import android.test.AndroidTestCase;
import android.test.MoreAsserts;

public class AntSensorManagerTest extends AndroidTestCase {
  private class TestAntSensorManager extends AntSensorManager {
    public byte messageId;
    public byte[] messageData;

    public TestAntSensorManager() {
      super(null);
    }

    @Override
    protected void setupAntSensorChannels() {}

    @SuppressWarnings("deprecation")
    @Override
    public void handleMessage(byte[] rawMessage) {
      super.handleMessage(rawMessage);
    }

    @SuppressWarnings("hiding")
    @Override
    public boolean handleMessage(byte messageId, byte[] messageData) {
      this.messageId = messageId;
      this.messageData = messageData;
      return true;
    }
  }

  private final TestAntSensorManager sensorManager = new TestAntSensorManager();

  public void testSimple() {
    byte[] rawMessage = {
        0x03,              // length
        0x12,              // message id
        0x11, 0x22, 0x33,  // body
    };

    byte[] expectedBody = { 0x11, 0x22, 0x33 };

    sensorManager.handleMessage(rawMessage);
    assertEquals((byte) 0x12, sensorManager.messageId);
    MoreAsserts.assertEquals(expectedBody, sensorManager.messageData);
  }

  public void testTooShort() {
    byte[] rawMessage = {
        0x53,  // length
        0x12   // message id
    };

    sensorManager.handleMessage(rawMessage);
    assertEquals(0, sensorManager.messageId);
    assertNull(sensorManager.messageData);
  }

  public void testLengthWrong() {
    byte[] rawMessage = {
        0x53,  // length
        0x12,  // message id
        0x34,  // body
    };

    sensorManager.handleMessage(rawMessage);
    assertEquals(0, sensorManager.messageId);
    assertNull(sensorManager.messageData);
  }
}

@@ -659,80 +659,32 @@
 ort 
-com.google.android.apps.mytracks.services.sensors.ant.A
+android.co
 nt
-S
 en
-sorManager;%0A
+t.Context;
 %0Aimp
@@ -875,16 +875,17 @@
 nager %7B%0A
+%0A
     publ
@@ -891,23 +891,76 @@
 lic 
-byte messageId;
+TestAntSensorManager(Context context) %7B%0A      super(context);%0A    %7D%0A
 %0A   
@@ -967,34 +967,32 @@
  public byte
-%5B%5D
  message
 Data;%0A%0A    p
@@ -979,22 +979,19 @@
  message
-Data;%0A
+Id;
 %0A    pub
@@ -998,57 +998,27 @@
 lic 
-TestAntSensorManager() %7B%0A      super(null);%0A    %7D
+byte%5B%5D messageData;
 %0A%0A  
@@ -1458,14 +1458,8 @@
 ate 
-final 
 Test
@@ -1475,16 +1475,113 @@
 Manager 
+sensorManager;%0A  %0A  @Override%0A  protected void setUp() throws Exception %7B%0A    super.setUp();%0A    
 sensorMa
@@ -1613,18 +1613,36 @@
 Manager(
-);
+getContext());%0A  %7D  
 %0A%0A  publ

fix unit test due to AntSensorManager changes