English subtitles

← ReadWrite from Location Table Solution - Developing Android Apps

Get Embed Code
6 Languages

Showing Revision 10 created 05/25/2016 by Udacity Robot.

  1. Here's what the testLocationTable
    method looks like.
  2. First, we grab a reference
    to a writable database
  3. because we'll be modifying the database.
  4. Then we create content values for
  5. a row of location data using
    the function within test utilities.
  6. Then we insert that content values
    object into the location table.
  7. The return value of the insert
    statement should be row ID.
  8. If it's negative one, we know
    the insertion failed, so we assert that.
  9. Then we query the location table and
    pass in null for all the parameters
  10. to get a default query of all tabled
    rows and columns, since we want
  11. a precisely verify that our database
    only contains our inserted record.
  12. The query will return a cursor.
  13. And we are assert if we cannot
    move it to the first row.
  14. Finally, we call validate current record
    from the test utility to validate
  15. the query will return
    the correct record.
  16. Validate current record
    grabs the set of value pairs
  17. from the content values
    that we inserted.
  18. It then iterates through them,
    using cursor.getColumnIndex
  19. to get the index of each column
    in the record set by name.
  20. We need the column index to
    get data from the cursor.
  21. Note the projections
    are always return in order.
  22. So if we specify a projection,
    we can safely use the indexes from our
  23. projection array without having
    to look them up like this.
  24. Let's go back to our test.
  25. We checked to make sure the database has
    only one record by making sure we moved
  26. to next fails, then we close the cursor
    and database, we don't leak resources.
  27. Finally, we return the locationRowId.
  28. Let's run the test and see what happens.
  29. And the test past, [SOUND],
    only one more test to write.