@Test public void testParseHexOrDefaultOk() throws Exception { long i = 0x12; String s = "0x" + Long.toHexString(i); int def = 14; assertEquals(i, ParseLong.parseHexOrDefault(s, def)); }
@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 testParseDecOrDefaultOk() throws Exception { long i = 12; String s = Long.toString(i); int def = 14; assertEquals(i, ParseLong.parseDecOrDefault(s, def)); }
@Test public void testParseHexOptionalOk() throws Exception { long i = 0x14; String s = Long.toHexString(i); OptionalLong ret = ParseLong.parseHexOptional(s); assertTrue(ret.isPresent()); assertEquals(i, ret.getAsLong()); }
@Test public void testParseHexPrefixEquals() throws Exception { long i = 123456; String s = Long.toHexString(i); String s1 = "0x" + s; String s2 = "0X" + s; // Transitive property means we only have to test twice assertEquals(ParseLong.parseHex(s), ParseLong.parseHex(s1)); assertEquals(ParseLong.parseHex(s1), ParseLong.parseHex(s2)); }
// @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()); } }
private String getUniqueId() { return Long.toHexString(Double.doubleToLongBits(Math.random())); }
@Test public void testParseDec_MaxSigned() throws Exception { long i = Long.MAX_VALUE; String s = Long.toString(i); assertEquals(i, ParseLong.parseDec(s)); }
// Test negative sign prefix @Test public void testParseDec_Negative() throws Exception { long i = -123456; String s = Long.toString(i); assertEquals(i, ParseLong.parseDec(s)); }
// Test dec/hex hex trimming @Test public void testParse_HexTrim() throws Exception { long i = 0x123ABC; String s = WHITESPACE + "0x" + Long.toHexString(i) + WHITESPACE; assertEquals(i, ParseLong.parse(s)); }
// Test dec/hex dec trimming @Test public void testParse_DecTrim() throws Exception { long i = 123456; String s = WHITESPACE + Long.toString(i) + WHITESPACE; assertEquals(i, ParseLong.parse(s)); }
// Test dec/hex picking @Test public void testParse_Hex() throws Exception { long i = 0x123ABC; String s = "0x" + Long.toHexString(i); assertEquals(i, ParseLong.parse(s)); }
// Test dec/hex picking @Test public void testParse_Dec() throws Exception { long i = 123456; String s = Long.toString(i); assertEquals(i, ParseLong.parse(s)); }
// Technically this is the same as MaxUnsigned @Test public void testParseHexMinSigned() throws Exception { long i = Long.MIN_VALUE; String s = "0x" + Long.toHexString(i); assertEquals(i, ParseLong.parseHex(s)); }