@Test(timeout = 1000) public void testSameSourceMultipleIterators() { TestScheduler scheduler = new TestScheduler(); NbpBlockingObservable<Long> source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable<Long> iter = source.latest(); for (int j = 0; j < 3; j++) { Iterator<Long> it = iter.iterator(); // only 9 because take(10) will immediately call onCompleted when receiving the 10th item // which onCompleted will overwrite the previous value for (int i = 0; i < 9; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); Assert.assertEquals(true, it.hasNext()); Assert.assertEquals(Long.valueOf(i), it.next()); } scheduler.advanceTimeBy(1, TimeUnit.SECONDS); Assert.assertEquals(false, it.hasNext()); } }
// @Test public void testInsert() throws SQLException { if (!((CreatebleDao) dao).tableExist()) { ((CreatebleDao) dao).createTable(); } spread = new Spread(); spread.setAmount(Integer.valueOf(500)); spread.setDate("29/06/2013"); spread.setFlockId(Long.valueOf(1)); spread.setNumberAccount(Integer.valueOf(5)); spread.setPrice(Float.valueOf("12.34")); spread.setTotal(Float.valueOf("10.25")); dao.insert(spread); assertEquals(5, dao.getAllByFlockId(flockId).size()); List<Spread> spreads = dao.getAllByFlockId(flockId); for (Spread g : spreads) { System.out.println(g); } }
@Test(timeout = 1000, expected = NoSuchElementException.class) public void testSimpleJustNext() { TestScheduler scheduler = new TestScheduler(); NbpBlockingObservable<Long> source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable<Long> iter = source.latest(); Iterator<Long> it = iter.iterator(); // only 9 because take(10) will immediately call onCompleted when receiving the 10th item // which onCompleted will overwrite the previous value for (int i = 0; i < 10; i++) { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); Assert.assertEquals(Long.valueOf(i), it.next()); } }
/** @author Administrator */ @Ignore public class DerbySpreadDaoTest { private Long flockId = Long.valueOf(1); private Spread spread; private SpreadDao dao; public DerbySpreadDaoTest() {} @BeforeClass public static void setUpClass() throws Exception {} @AfterClass public static void tearDownClass() throws Exception {} @Before public void setUp() { dao = DbImplDecider.use(DaoType.MYSQL).getDao(SpreadDao.class); } @Test public void testCreateTable() throws SQLException { if (!((CreatebleDao) dao).tableExist()) { ((CreatebleDao) dao).createTable(); } assertTrue(((CreatebleDao) dao).tableExist()); } // @Test public void testDropTable() throws SQLException { ((DerbySpreadDaoImpl) dao).dropTable(); assertFalse(((CreatebleDao) dao).tableExist()); } // @Test public void testInsert() throws SQLException { if (!((CreatebleDao) dao).tableExist()) { ((CreatebleDao) dao).createTable(); } spread = new Spread(); spread.setAmount(Integer.valueOf(500)); spread.setDate("29/06/2013"); spread.setFlockId(Long.valueOf(1)); spread.setNumberAccount(Integer.valueOf(5)); spread.setPrice(Float.valueOf("12.34")); spread.setTotal(Float.valueOf("10.25")); dao.insert(spread); assertEquals(5, dao.getAllByFlockId(flockId).size()); List<Spread> spreads = dao.getAllByFlockId(flockId); for (Spread g : spreads) { System.out.println(g); } } // @Test public void testRemove() throws SQLException { dao.remove(spread.getId()); spread = dao.getById(flockId); assertNull(spread); } // @Test public void testRemoveAll() throws SQLException { List<Spread> spreadList = dao.getAllByFlockId(flockId); for (Spread g : spreadList) { dao.remove(g.getId()); } spreadList = dao.getAllByFlockId(flockId); assertEquals(0, spreadList.size()); } }