<- ReadMe.html  ||  <- ../Functionality.html

goodViberations: Data Layer Unit Tests

Introduction

The data layer classes need unit tests to verify that the code works as expected. The class DataLayer has a corresponding unit test class called DataLayerUnitTests in the com.j3t.datalayer.datalayer package. Below is a table that enumerates the unit test methods' functionality in DataLayerUnitTests.

MethodDescription
beforeEach This method is annotated to run before each test (@BeforeEach method annotation). Two class variables are created: dataEntry1 and dataEntry2 as follows:
  1. creates a DataField instance variable called field1, with the following values:
      name = "testFieldName1",
      value = "testFieldValue1"
  2. another DataField instance variable called field12 with the following values:
      name = "testFieldName2",
      value = "testFieldValue2"
  3. creates a DataEntry instance variable called dataEntry1, with the following values:
      name = "testName1",
      notes = "testNotes",
      password = "testPassword"
  4. field1 and field2 are added to the dataEntry1 instance variable detailFields.
  5. creates a DataField instance variable called field3 with the following values:
      name = "testFieldName3,
      value = "testFieldValue3"
  6. another DataField instance variable called field4 with the following values:
      name = "testFieldName4",
      value = "testFieldValue4"
  7. creates a DataEntry instance variable called dataEntry2, with the following values:
      name = "testName2",
      notes = "testNotes",
      password = "testPassword"
  8. field2 and field3 are added to the dataEntry2 instance variable detailFields.
All the existing data files in the context.filesDir are deleted.
saveStoreTest The following operations are carried out by this method:
  1. saveStore is called with the map of dataEntry1
  2. the context.filesDir number of files is counted, it must equal 1.
  3. saveStore is called with the map of dataEntry1 and dataEntry2.
  4. the number of files in context.filesDir is counted, it must equal 2.
createStoreTest createStore is called with the map of dataEntry1 and dataEntry2.
The count of files in context.filesDir is checked, it must equal 1.
loadStoreTest
  1. saveStore is called with the map of dataEntry2 and dataEntry1.
  2. loadStore is called, the returned map is checked as follows:
    • The first dataEntry instance in the map hase the name "testName1"
        The first dataEntry instance notes = "testNotes", the key to the map is the dataEntry instance name field converted to lower case.
        The first dataEntry instance password = "testPassword"
    • The second dataEntry instance in the map has the name "testName2", the key to the map is the dataEntry instance name field converted to lower case.
loadEntryTest
  1. saveStore is called with the map of dataEntry2 and dataEntry1.
  2. loadEntry is called, with the parameter name given as "testName2". The returned DataEntry is checked as follows:
    • The DataEntry instance has the name "testName2".
    • The DataEntry instance has the password "testPassword".
  3. loadEntry is called, with the parameter name given as "testName". The returned DataEntry is saved in the variable dataEntry. The returned DataEntry is checked as follows:
    • The dataEntry instance has the name "entry testName not found".
deleteStoreTest saveStore is called with the map of dataEntry2
saveStore is called with the map of dataEntry2 and dataEntry1.
deleteStore is called
a check is made to ensure there are no files in the context.filesDir
listEntryNamesTest
  1. saveStore is called with the map of dataEntry2 and dataEntry1.
  2. listEntryNames is called, the returned list is checked as follows:
    • The first entry in the list has the value "testName1"
    • The second dataEntry instance in the list has the value "testName2"
storeExistsTest storeExists is called to check that it returns false
saveStore is called with the map of dataEntry2
storeExists is called to check that it returns true