Ejemplo n.º 1
0
  @Test
  public void createMethodGetterAndSetterTest() {
    Book book = new Book();
    book.setDateRecieved(new Date());
    book.setRecieved(true);
    book.setReciever("some");

    Dao<Integer, Book> dao = dbLite.getDao(Book.class);
    long id = dao.create(book);
    Assert.assertTrue(id > 0);
  }
Ejemplo n.º 2
0
  @Test(expected = NoSuitablePrimaryKeySuppliedException.class)
  public void primaryKeyAutoGenerationTest() {
    Book book = new Book();
    Dao<Long, Book> dao = dbLite.getDao(Book.class);
    long id = dao.create(book);

    Assert.assertTrue("pimary key not auto generated", id > 0);

    book.setId(10);
    id = dao.create(book);
    Assert.assertTrue("primary key not created manually", id == 10);

    // Test Non Numeric PrimaryKey
    NonNumeric nonNumeric = new NonNumeric();
    Dao<String, NonNumeric> dao2 = dbLite.getDao(NonNumeric.class);
    id = dao2.create(nonNumeric); // should throw NoSuitablePrimaryKeySuppliedException

    nonNumeric.setId("mdennis");
    id = dao2.create(nonNumeric);
    Assert.assertTrue("Entity with Non-Numeric primary key not stored", id > 0);
  }
Ejemplo n.º 3
0
  @Test
  public void dateEqualityTest() throws ParseException {
    Book book = new Book();
    book.setId(1);
    book.setReciever("Mario");
    book.setAmountSent(2);
    SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
    Date date = sdf.parse("24/11/2014");
    book.setDateRecieved(date);

    Dao<Integer, Book> dao = dbLite.getDao(Book.class);
    long rowID = dao.create(book);
    Assert.assertEquals(book.getId(), rowID);

    Book book2 = new Book();
    book2.setId(2);
    book2.setReciever("Mario");
    book2.setAmountSent(2);
    book2.setDateRecieved(new Date());

    long rowID2 = dao.create(book2);
    Assert.assertEquals(book2.getId(), rowID2);

    List<Book> books = dao.findAll(null, null, "dateRecieved > ?", date);
    Assert.assertTrue(books.size() > 0);
  }
Ejemplo n.º 4
0
  @Test
  public void privateFieldsGetterAndSetterMethodTest() {
    Book book = new Book();
    book.setId(1);
    book.setReciever("Mario");
    book.setAmountSent(2);
    book.setDateRecieved(new Date());
    book.setRecieved(true);

    Dao<Integer, Book> dao = dbLite.getDao(Book.class);
    long rowID = dao.create(book);
    Assert.assertEquals(book.getId(), rowID);

    Book bookDB = dao.findById(book.getId());
    Assert.assertEquals(book.getReciever(), bookDB.getReciever());
    Assert.assertEquals(book.getAmountSent(), bookDB.getAmountSent());
    Assert.assertEquals(book.isRecieved(), bookDB.isRecieved());
    Assert.assertEquals(book.getDateRecieved(), bookDB.getDateRecieved());
  }