diff --git a/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageStoreTest.scala b/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageStoreTest.scala index 113fdf5..43545f8 100644 --- a/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageStoreTest.scala +++ b/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageStoreTest.scala @@ -7,6 +7,7 @@ import android.database.DatabaseErrorHandler import android.database.sqlite.SQLiteDatabase import android.test.AndroidTestCase import android.test.mock.MockContext +import android.util.Log import com.nutomic.ensichat.bluetooth.Device import com.nutomic.ensichat.messages.MessageTest._ import junit.framework.Assert._ @@ -38,20 +39,20 @@ class MessageStoreTest extends AndroidTestCase { } def testCount(): Unit = { - val msg1 = MessageStore.getMessages(new Device.ID("one"), 1) + val msg1 = MessageStore.getMessages(m1.sender, 1) assertEquals(1, msg1.size) - val msg2 = MessageStore.getMessages(new Device.ID("one"), 3) + val msg2 = MessageStore.getMessages(m1.sender, 3) assertEquals(2, msg2.size) } def testOrder(): Unit = { - val msg = MessageStore.getMessages(new Device.ID("two"), 1) + val msg = MessageStore.getMessages(m1.receiver, 1) assertTrue(msg.contains(m3)) } def testSelect(): Unit = { - val msg = MessageStore.getMessages(new Device.ID("two"), 2) + val msg = MessageStore.getMessages(m1.receiver, 2) assertTrue(msg.contains(m1)) assertTrue(msg.contains(m3)) } diff --git a/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageTest.scala b/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageTest.scala index d9a5336..2802570 100644 --- a/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageTest.scala +++ b/app/src/androidTest/scala/com.nutomic.ensichat.messages/MessageTest.scala @@ -12,13 +12,13 @@ import scala.collection.immutable.TreeSet object MessageTest { - val m1 = new TextMessage(new Device.ID("one"), new Device.ID("two"), + val m1 = new TextMessage(new Device.ID("AA:AA:AA:AA:AA:AA"), new Device.ID("BB:BB:BB:BB:BB:BB"), new GregorianCalendar(2014, 10, 29).getTime, "first") - val m2 = new TextMessage(new Device.ID("one"), new Device.ID("three"), + val m2 = new TextMessage(new Device.ID("AA:AA:AA:AA:AA:AA"), new Device.ID("CC:CC:CC:CC:CC:CC"), new GregorianCalendar(2014, 10, 30).getTime, "second") - val m3 = new TextMessage(new Device.ID("four"), new Device.ID("two"), + val m3 = new TextMessage(new Device.ID("DD:DD:DD:DD:DD:DD"), new Device.ID("BB:BB:BB:BB:BB:BB"), new GregorianCalendar(2014, 10, 31).getTime, "third") diff --git a/app/src/main/scala/com/nutomic/ensichat/bluetooth/Device.scala b/app/src/main/scala/com/nutomic/ensichat/bluetooth/Device.scala index 9761047..afc0f60 100644 --- a/app/src/main/scala/com/nutomic/ensichat/bluetooth/Device.scala +++ b/app/src/main/scala/com/nutomic/ensichat/bluetooth/Device.scala @@ -10,12 +10,17 @@ object Device { * @param Id A bluetooth device address. */ class ID(private val Id: String) { + require(Id.matches("([A-Z0-9][A-Z0-9]:){5}[A-Z0-9][A-Z0-9]"), "Invalid device ID format") + override def hashCode = Id.hashCode + override def equals(a: Any) = a match { case other: Device.ID => Id == other.Id case _ => false } + override def toString = Id + } }