How to use assertFalse method of junit.framework.Assert class

Best junit code snippet using junit.framework.Assert.assertFalse

Source:TestOdbcTypes.java Github

copy

Full Screen

...40import org.junit.BeforeClass;41import org.junit.Ignore;42import org.junit.Test;43import static junit.framework.Assert.assertEquals;44import static junit.framework.Assert.assertFalse;45import static junit.framework.Assert.assertTrue;46/**47 * See TestOdbcBase for more general ODBC test information.48 *49 * This class has been converted to JUnit 4.10.50 * Test runs are faster than the JUnit 3.x original with one-time-per-class51 * setUp and tearDown (fredt@users).52 * <p>53 *54 * @author Blaine Simpson (blaine dot simpson at admc dot com)55 * @since 1.9.056 * @see TestOdbcBase57 */58public class TestOdbcTypes extends TestOdbcBase {59 /* HyperSQL types to be tested:60 *61 * Exact Numeric62 * TINYINT63 * SMALLINT64 * INTEGER65 * BIGINT66 * NUMERIC(p?,s?) = DECIMAL() (default for decimal literals)67 * Approximate Numeric68 * FLOAT(p?)69 * DOUBLE = REAL (default for literals with exponent)70 * BOOLEAN71 * Character Strings72 * CHARACTER(1l)* = CHAR()73 * CHARACTER VARYING(1l) = VARCHAR() = LONGVARCHAR()74 * CLOB(1l) = CHARACTER LARGE OBJECT(1)75 * Binary Strings76 * BINARY(1l)*77 * BINARY VARYING(1l) = VARBINARY()78 * BLOB(1l) = BINARY LARGE OBJECT()79 * Bits80 * BIT(1l)81 * BIT VARYING(1l)82 * OTHER (for holding serialized Java objects)83 * Date/Times84 * DATE85 * TIME(p?,p?)86 * TIMESTAMP(p?,p?)87 * INTERVAL...(p2,p0)88 */89 public TestOdbcTypes() {}90 @BeforeClass91 public static void setUpForTests() {92 setUpServer();93 }94 @AfterClass95 public static void tearDownClass() throws SQLException {96 tearDownServer();97 }98 @Before99 public void setUp() throws Exception {100 super.setUp();101 }102 protected void populate(Statement st) throws SQLException {103 st.executeUpdate("DROP TABLE alltypes IF EXISTS");104 st.executeUpdate("CREATE TABLE alltypes (\n" + " id INTEGER,\n"105 + " ti TINYINT,\n" + " si SMALLINT,\n"106 + " i INTEGER,\n" + " bi BIGINT,\n"107 + " n NUMERIC(5,2),\n" + " f FLOAT(5),\n"108 + " r DOUBLE,\n" + " b BOOLEAN,\n"109 + " c CHARACTER(3),\n"110 + " cv CHARACTER VARYING(3),\n"111 + " bt BIT(9),\n" + " btv BIT VARYING(3),\n"112 + " d DATE,\n" + " t TIME(2),\n"113 + " tw TIME(2) WITH TIME ZONE,\n"114 + " ts TIMESTAMP(2),\n"115 + " tsw TIMESTAMP(2) WITH TIME ZONE,\n"116 + " bin BINARY(4),\n" + " vb VARBINARY(4),\n"117 + " dsival INTERVAL DAY(5) TO SECOND(6),\n"118 + " sival INTERVAL SECOND(6,4)\n" + ')');119 // Would be more elegant and efficient to use a prepared statement120 // here, but our we want this setup to be as simple as possible, and121 // leave feature testing for the actual unit tests.122 st.executeUpdate(123 "INSERT INTO alltypes VALUES (\n"124 + " 1, 3, 4, 5, 6, 7.8, 8.9, 9.7, true, 'ab', 'cd',\n"125 + " b'10', b'10', current_date, '13:14:00',\n"126 + " '15:16:00', '2009-02-09 16:17:18', '2009-02-09 17:18:19',\n"127 + " x'A103', x'A103', "128 + "INTERVAL '145 23:12:19.345' DAY TO SECOND,\n"129 + " INTERVAL '1000.345' SECOND\n" + ')');130 st.executeUpdate(131 "INSERT INTO alltypes VALUES (\n"132 + " 2, 3, 4, 5, 6, 7.8, 8.9, 9.7, true, 'ab', 'cd',\n"133 + " b'10', b'10', current_date, '13:14:00',\n"134 + " '15:16:00', '2009-02-09 16:17:18', '2009-02-09 17:18:19',\n"135 + " x'A103', x'A103', "136 + " INTERVAL '145 23:12:19.345' DAY TO SECOND,\n"137 + " INTERVAL '1000.345' SECOND\n" + ')');138 }139 @Test140 public void testIntegerSimpleRead() {141 ResultSet rs = null;142 Statement st = null;143 try {144 st = netConn.createStatement();145 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");146 assertTrue("Got no rows with id in (1, 2)", rs.next());147 assertEquals(Integer.class, rs.getObject("i").getClass());148 assertTrue("Got only one row with id in (1, 2)", rs.next());149 assertEquals(5, rs.getInt("i"));150 assertFalse("Got too many rows with id in (1, 2)", rs.next());151 } catch (SQLException se) {152 junit.framework.AssertionFailedError ase =153 new junit.framework.AssertionFailedError(se.getMessage());154 ase.initCause(se);155 throw ase;156 } finally {157 try {158 if (rs != null) {159 rs.close();160 }161 if (st != null) {162 st.close();163 }164 } catch (Exception ignored) {}165 }166 }167 @Test168 public void testTinyIntSimpleRead() {169 ResultSet rs = null;170 Statement st = null;171 try {172 st = netConn.createStatement();173 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");174 assertTrue("Got no rows with id in (1, 2)", rs.next());175 Object o = rs.getObject("ti"); // todo - returns string176 // assertEquals(Integer.class, rs.getObject("ti").getClass());177 // Nb. HyperSQL purposefully returns an Integer for this type178 assertTrue("Got only one row with id in (1, 2)", rs.next());179 assertEquals((byte) 3, rs.getByte("ti"));180 assertFalse("Got too many rows with id in (1, 2)", rs.next());181 } catch (SQLException se) {182 junit.framework.AssertionFailedError ase =183 new junit.framework.AssertionFailedError(se.getMessage());184 ase.initCause(se);185 throw ase;186 } finally {187 try {188 if (rs != null) {189 rs.close();190 }191 if (st != null) {192 st.close();193 }194 } catch (Exception ignored) {}195 }196 }197 @Test198 public void testSmallIntSimpleRead() {199 ResultSet rs = null;200 Statement st = null;201 try {202 st = netConn.createStatement();203 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");204 assertTrue("Got no rows with id in (1, 2)", rs.next());205 assertEquals(Integer.class, rs.getObject("si").getClass());206 // Nb. HyperSQL purposefully returns an Integer for this type207 assertTrue("Got only one row with id in (1, 2)", rs.next());208 assertEquals((short) 4, rs.getShort("si"));209 assertFalse("Got too many rows with id in (1, 2)", rs.next());210 } catch (SQLException se) {211 junit.framework.AssertionFailedError ase =212 new junit.framework.AssertionFailedError(se.getMessage());213 ase.initCause(se);214 throw ase;215 } finally {216 try {217 if (rs != null) {218 rs.close();219 }220 if (st != null) {221 st.close();222 }223 } catch (Exception ignored) {}224 }225 }226 @Test227 public void testBigIntSimpleRead() {228 ResultSet rs = null;229 Statement st = null;230 try {231 st = netConn.createStatement();232 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");233 assertTrue("Got no rows with id in (1, 2)", rs.next());234 assertEquals(Long.class, rs.getObject("bi").getClass());235 assertTrue("Got only one row with id in (1, 2)", rs.next());236 assertEquals(6, rs.getLong("bi"));237 assertFalse("Got too many rows with id in (1, 2)", rs.next());238 } catch (SQLException se) {239 junit.framework.AssertionFailedError ase =240 new junit.framework.AssertionFailedError(se.getMessage());241 ase.initCause(se);242 throw ase;243 } finally {244 try {245 if (rs != null) {246 rs.close();247 }248 if (st != null) {249 st.close();250 }251 } catch (Exception ignored) {}252 }253 }254 @Test255 public void testNumericSimpleRead() {256 // This is failing.257 // Looks like we inherited a real bug with numerics from psqlodbc,258 // because the problem exists with Postresql-supplied psqlodbc259 // connecting to a Postgresql server.260 ResultSet rs = null;261 Statement st = null;262 try {263 st = netConn.createStatement();264 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");265 assertTrue("Got no rows with id in (1, 2)", rs.next());266 Object o = rs.getObject("n");267 assertEquals(BigDecimal.class, o.getClass());268 assertTrue("Got only one row with id in (1, 2)", rs.next());269 o = rs.getBigDecimal("n"); // todo - wrong result270 BigDecimal expected = new BigDecimal("7.80");271 assertEquals(expected, o);272 assertFalse("Got too many rows with id in (1, 2)", rs.next());273 } catch (SQLException se) {274 junit.framework.AssertionFailedError ase275 = new junit.framework.AssertionFailedError(se.getMessage());276 ase.initCause(se);277 throw ase;278 } finally {279 try {280 if (rs != null) {281 rs.close();282 }283 if (st != null) {284 st.close();285 }286 } catch(Exception ignored) {287 }288 }289 }290 @Test291 public void testFloatSimpleRead() {292 ResultSet rs = null;293 Statement st = null;294 try {295 st = netConn.createStatement();296 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");297 assertTrue("Got no rows with id in (1, 2)", rs.next());298 assertEquals(Double.class, rs.getObject("f").getClass());299 assertTrue("Got only one row with id in (1, 2)", rs.next());300 assertEquals(8.9D, rs.getDouble("f"), 0D);301 assertFalse("Got too many rows with id in (1, 2)", rs.next());302 } catch (SQLException se) {303 junit.framework.AssertionFailedError ase =304 new junit.framework.AssertionFailedError(se.getMessage());305 ase.initCause(se);306 throw ase;307 } finally {308 try {309 if (rs != null) {310 rs.close();311 }312 if (st != null) {313 st.close();314 }315 } catch (Exception ignored) {}316 }317 }318 @Test319 public void testDoubleSimpleRead() {320 ResultSet rs = null;321 Statement st = null;322 try {323 st = netConn.createStatement();324 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");325 assertTrue("Got no rows with id in (1, 2)", rs.next());326 assertEquals(Double.class, rs.getObject("r").getClass());327 assertTrue("Got only one row with id in (1, 2)", rs.next());328 assertEquals(9.7D, rs.getDouble("r"), 0D);329 assertFalse("Got too many rows with id in (1, 2)", rs.next());330 } catch (SQLException se) {331 junit.framework.AssertionFailedError ase =332 new junit.framework.AssertionFailedError(se.getMessage());333 ase.initCause(se);334 throw ase;335 } finally {336 try {337 if (rs != null) {338 rs.close();339 }340 if (st != null) {341 st.close();342 }343 } catch (Exception ignored) {}344 }345 }346 // todo347 @Test348 public void testBooleanSimpleRead() {349 ResultSet rs = null;350 Statement st = null;351 try {352 st = netConn.createStatement();353 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");354 assertTrue("Got no rows with id in (1, 2)", rs.next());355 Object o = rs.getObject("b"); // todo - returns string356 // assertEquals(Boolean.class, o.getClass());357 assertTrue("Got only one row with id in (1, 2)", rs.next());358 assertTrue(rs.getBoolean("b"));359 assertFalse("Got too many rows with id in (1, 2)", rs.next());360 } catch (SQLException se) {361 junit.framework.AssertionFailedError ase =362 new junit.framework.AssertionFailedError(se.getMessage());363 ase.initCause(se);364 throw ase;365 } finally {366 try {367 if (rs != null) {368 rs.close();369 }370 if (st != null) {371 st.close();372 }373 } catch (Exception ignored) {}374 }375 }376 @Test377 public void testCharSimpleRead() {378 ResultSet rs = null;379 Statement st = null;380 try {381 st = netConn.createStatement();382 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");383 assertTrue("Got no rows with id in (1, 2)", rs.next());384 assertEquals(String.class, rs.getObject("c").getClass());385 assertTrue("Got only one row with id in (1, 2)", rs.next());386 assertEquals("ab ", rs.getString("c"));387 assertFalse("Got too many rows with id in (1, 2)", rs.next());388 } catch (SQLException se) {389 junit.framework.AssertionFailedError ase =390 new junit.framework.AssertionFailedError(se.getMessage());391 ase.initCause(se);392 throw ase;393 } finally {394 try {395 if (rs != null) {396 rs.close();397 }398 if (st != null) {399 st.close();400 }401 } catch (Exception ignored) {}402 }403 }404 @Test405 public void testVarCharSimpleRead() {406 ResultSet rs = null;407 Statement st = null;408 try {409 st = netConn.createStatement();410 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");411 assertTrue("Got no rows with id in (1, 2)", rs.next());412 assertEquals(String.class, rs.getObject("cv").getClass());413 assertTrue("Got only one row with id in (1, 2)", rs.next());414 assertEquals("cd", rs.getString("cv"));415 assertFalse("Got too many rows with id in (1, 2)", rs.next());416 } catch (SQLException se) {417 junit.framework.AssertionFailedError ase =418 new junit.framework.AssertionFailedError(se.getMessage());419 ase.initCause(se);420 throw ase;421 } finally {422 try {423 if (rs != null) {424 rs.close();425 }426 if (st != null) {427 st.close();428 }429 } catch (Exception ignored) {}430 }431 }432 @Test433 public void testFixedStringSimpleRead() {434 ResultSet rs = null;435 Statement st = null;436 try {437 st = netConn.createStatement();438 rs = st.executeQuery("SELECT i, 'fixed str' fs, cv\n"439 + "FROM alltypes WHERE id in (1, 2)");440 assertTrue("Got no rows with id in (1, 2)", rs.next());441 assertEquals(String.class, rs.getObject("fs").getClass());442 assertTrue("Got only one row with id in (1, 2)", rs.next());443 assertEquals("fixed str", rs.getString("fs"));444 assertFalse("Got too many rows with id in (1, 2)", rs.next());445 } catch (SQLException se) {446 junit.framework.AssertionFailedError ase =447 new junit.framework.AssertionFailedError(se.getMessage());448 ase.initCause(se);449 throw ase;450 } finally {451 try {452 if (rs != null) {453 rs.close();454 }455 if (st != null) {456 st.close();457 }458 } catch (Exception ignored) {}459 }460 }461 @Test462 public void testDerivedStringSimpleRead() {463 ResultSet rs = null;464 Statement st = null;465 try {466 st = netConn.createStatement();467 rs = st.executeQuery("SELECT i, cv || 'appendage' app, 4\n"468 + "FROM alltypes WHERE id in (1, 2)");469 assertTrue("Got no rows with id in (1, 2)", rs.next());470 assertEquals(String.class, rs.getObject("app").getClass());471 assertTrue("Got only one row with id in (1, 2)", rs.next());472 assertEquals("cdappendage", rs.getString("app"));473 assertFalse("Got too many rows with id in (1, 2)", rs.next());474 } catch (SQLException se) {475 junit.framework.AssertionFailedError ase =476 new junit.framework.AssertionFailedError(se.getMessage());477 ase.initCause(se);478 throw ase;479 } finally {480 try {481 if (rs != null) {482 rs.close();483 }484 if (st != null) {485 st.close();486 }487 } catch (Exception ignored) {}488 }489 }490 @Test491 public void testDateSimpleRead() {492 ResultSet rs = null;493 Statement st = null;494 try {495 st = netConn.createStatement();496 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");497 assertTrue("Got no rows with id in (1, 2)", rs.next());498 assertEquals(java.sql.Date.class, rs.getObject("d").getClass());499 assertTrue("Got only one row with id in (1, 2)", rs.next());500 assertEquals(501 new java.sql.Date(new java.util.Date().getTime()).toString(),502 rs.getDate("d").toString());503 assertFalse("Got too many rows with id in (1, 2)", rs.next());504 } catch (SQLException se) {505 junit.framework.AssertionFailedError ase =506 new junit.framework.AssertionFailedError(se.getMessage());507 ase.initCause(se);508 throw ase;509 } finally {510 try {511 if (rs != null) {512 rs.close();513 }514 if (st != null) {515 st.close();516 }517 } catch (Exception ignored) {}518 }519 }520 @Test521 public void testTimeSimpleRead() {522 ResultSet rs = null;523 Statement st = null;524 try {525 st = netConn.createStatement();526 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");527 assertTrue("Got no rows with id in (1, 2)", rs.next());528 assertEquals(java.sql.Time.class, rs.getObject("t").getClass());529 assertTrue("Got only one row with id in (1, 2)", rs.next());530 assertEquals(Time.valueOf("13:14:00"), rs.getTime("t"));531 assertFalse("Got too many rows with id in (1, 2)", rs.next());532 } catch (SQLException se) {533 junit.framework.AssertionFailedError ase =534 new junit.framework.AssertionFailedError(se.getMessage());535 ase.initCause(se);536 throw ase;537 } finally {538 try {539 if (rs != null) {540 rs.close();541 }542 if (st != null) {543 st.close();544 }545 } catch (Exception ignored) {}546 }547 }548 @Test549 public void testTimeWSimpleRead() {550 // This test is failing because the JDBC Driver is returning a551 // String instead of a Time oject for rs.getTime().552 ResultSet rs = null;553 Statement st = null;554 try {555 st = netConn.createStatement();556 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");557 assertTrue("Got no rows with id in (1, 2)", rs.next());558 Object o = rs.getObject("tw"); // todo - returns string 15:16:00.00+1:00559 // assertEquals(java.sql.Time.class, o.getClass());560 assertTrue("Got only one row with id in (1, 2)", rs.next());561 o = rs.getTime("tw"); // todo - wrong result - returns 1 hour562 // assertEquals(Time.valueOf("15:16:00"), o);563 assertFalse("Got too many rows with id in (1, 2)", rs.next());564 } catch (SQLException se) {565 junit.framework.AssertionFailedError ase566 = new junit.framework.AssertionFailedError(se.getMessage());567 ase.initCause(se);568 throw ase;569 } finally {570 try {571 if (rs != null) {572 rs.close();573 }574 if (st != null) {575 st.close();576 }577 } catch(Exception ignored) {578 }579 }580 }581 @Test582 public void testTimestampSimpleRead() {583 ResultSet rs = null;584 Statement st = null;585 try {586 st = netConn.createStatement();587 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");588 assertTrue("Got no rows with id in (1, 2)", rs.next());589 assertEquals(Timestamp.class, rs.getObject("ts").getClass());590 assertTrue("Got only one row with id in (1, 2)", rs.next());591 assertEquals(Timestamp.valueOf("2009-02-09 16:17:18"),592 rs.getTimestamp("ts"));593 assertFalse("Got too many rows with id in (1, 2)", rs.next());594 } catch (SQLException se) {595 junit.framework.AssertionFailedError ase =596 new junit.framework.AssertionFailedError(se.getMessage());597 ase.initCause(se);598 throw ase;599 } finally {600 try {601 if (rs != null) {602 rs.close();603 }604 if (st != null) {605 st.close();606 }607 } catch (Exception ignored) {}608 }609 }610 @Test611 public void testTimestampWSimpleRead() {612 ResultSet rs = null;613 Statement st = null;614 try {615 st = netConn.createStatement();616 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");617 assertTrue("Got no rows with id in (1, 2)", rs.next());618 assertEquals(Timestamp.class, rs.getObject("tsw").getClass());619 assertTrue("Got only one row with id in (1, 2)", rs.next());620 assertEquals(Timestamp.valueOf("2009-02-09 17:18:19"),621 rs.getTimestamp("tsw"));622 assertFalse("Got too many rows with id in (1, 2)", rs.next());623 } catch (SQLException se) {624 junit.framework.AssertionFailedError ase =625 new junit.framework.AssertionFailedError(se.getMessage());626 ase.initCause(se);627 throw ase;628 } finally {629 try {630 if (rs != null) {631 rs.close();632 }633 if (st != null) {634 st.close();635 }636 } catch (Exception ignored) {}637 }638 }639 @Test640 public void testBitSimpleRead() {641 // This test is failing because of a BIT padding bug in the engine.642 ResultSet rs = null;643 Statement st = null;644 try {645 st = netConn.createStatement();646 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");647 assertTrue("Got no rows with id in (1, 2)", rs.next());648 assertTrue("Got only one row with id in (1, 2)", rs.next());649 assertEquals("100000000", rs.getString("bt"));650 assertFalse("Got too many rows with id in (1, 2)", rs.next());651 } catch (SQLException se) {652 junit.framework.AssertionFailedError ase =653 new junit.framework.AssertionFailedError(se.getMessage());654 ase.initCause(se);655 throw ase;656 } finally {657 try {658 if (rs != null) {659 rs.close();660 }661 if (st != null) {662 st.close();663 }664 } catch (Exception ignored) {}665 }666 }667 @Test668 public void testBitVaryingSimpleRead() {669 ResultSet rs = null;670 Statement st = null;671 try {672 st = netConn.createStatement();673 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");674 assertTrue("Got no rows with id in (1, 2)", rs.next());675 assertTrue("Got only one row with id in (1, 2)", rs.next());676 assertEquals("10", rs.getString("btv"));677 assertFalse("Got too many rows with id in (1, 2)", rs.next());678 } catch (SQLException se) {679 junit.framework.AssertionFailedError ase =680 new junit.framework.AssertionFailedError(se.getMessage());681 ase.initCause(se);682 throw ase;683 } finally {684 try {685 if (rs != null) {686 rs.close();687 }688 if (st != null) {689 st.close();690 }691 } catch (Exception ignored) {}692 }693 }694 @Test695 public void testBinarySimpleRead() {696 ResultSet rs = null;697 Statement st = null;698 byte[] expectedBytes = new byte[] {699 (byte) 0xa1, (byte) 0x03, (byte) 0, (byte) 0700 };701 byte[] ba;702 try {703 st = netConn.createStatement();704 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");705 assertTrue("Got no rows with id in (1, 2)", rs.next());706 assertEquals("A1030000", rs.getString("bin"));707 assertTrue("Got only one row with id in (1, 2)", rs.next());708 ba = rs.getBytes("bin");709 assertFalse("Got too many rows with id in (1, 2)", rs.next());710 } catch (SQLException se) {711 junit.framework.AssertionFailedError ase =712 new junit.framework.AssertionFailedError(se.getMessage());713 ase.initCause(se);714 throw ase;715 } finally {716 try {717 if (rs != null) {718 rs.close();719 }720 if (st != null) {721 st.close();722 }723 } catch (Exception ignored) {}724 }725 assertEquals("Retrieved bye array length wrong", expectedBytes.length,726 ba.length);727 for (int i = 0; i < ba.length; i++) {728 assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);729 }730 }731 @Test732 public void testVarBinarySimpleRead() {733 ResultSet rs = null;734 Statement st = null;735 byte[] expectedBytes = new byte[] {736 (byte) 0xa1, (byte) 0x03737 };738 byte[] ba;739 try {740 st = netConn.createStatement();741 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");742 assertTrue("Got no rows with id in (1, 2)", rs.next());743 assertEquals("A103", rs.getString("vb"));744 assertTrue("Got only one row with id in (1, 2)", rs.next());745 ba = rs.getBytes("vb");746 assertFalse("Got too many rows with id in (1, 2)", rs.next());747 } catch (SQLException se) {748 junit.framework.AssertionFailedError ase =749 new junit.framework.AssertionFailedError(se.getMessage());750 ase.initCause(se);751 throw ase;752 } finally {753 try {754 if (rs != null) {755 rs.close();756 }757 if (st != null) {758 st.close();759 }760 } catch (Exception ignored) {}761 }762 assertEquals("Retrieved bye array length wrong", expectedBytes.length,763 ba.length);764 for (int i = 0; i < ba.length; i++) {765 assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);766 }767 }768 @Test769 public void testDaySecIntervalSimpleRead() {770 /* Since our client does not support the INTERVAL precision771 * constraints, the returned value will always be toString()'d to772 * precision of microseconds. */773 ResultSet rs = null;774 Statement st = null;775 try {776 st = netConn.createStatement();777 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");778 assertTrue("Got no rows with id in (1, 2)", rs.next());779 assertEquals("145 23:12:19.345000", rs.getString("dsival"));780 assertTrue("Got only one row with id in (1, 2)", rs.next());781 // Can't test the class, because jdbc:odbc or the driver returns782 // a String for getObject() for interval values.783 assertFalse("Got too many rows with id in (1, 2)", rs.next());784 } catch (SQLException se) {785 junit.framework.AssertionFailedError ase =786 new junit.framework.AssertionFailedError(se.getMessage());787 ase.initCause(se);788 throw ase;789 } finally {790 try {791 if (rs != null) {792 rs.close();793 }794 if (st != null) {795 st.close();796 }797 } catch (Exception ignored) {}798 }799 }800 @Test801 public void testSecIntervalSimpleRead() {802 /* Since our client does not support the INTERVAL precision803 * constraints, the returned value will always be toString()'d to804 * precision of microseconds. */805 ResultSet rs = null;806 Statement st = null;807 try {808 st = netConn.createStatement();809 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");810 assertTrue("Got no rows with id in (1, 2)", rs.next());811 assertEquals("1000.345000", rs.getString("sival"));812 assertTrue("Got only one row with id in (1, 2)", rs.next());813 // Can't test the class, because jdbc:odbc or the driver returns814 // a String for getObject() for interval values.815 assertFalse("Got too many rows with id in (1, 2)", rs.next());816 } catch (SQLException se) {817 junit.framework.AssertionFailedError ase =818 new junit.framework.AssertionFailedError(se.getMessage());819 ase.initCause(se);820 throw ase;821 } finally {822 try {823 if (rs != null) {824 rs.close();825 }826 if (st != null) {827 st.close();828 }829 } catch (Exception ignored) {}830 }831 }832 @Test833 public void testIntegerComplex() {834 PreparedStatement ps = null;835 ResultSet rs = null;836 try {837 ps = netConn.prepareStatement(838 "INSERT INTO alltypes(id, i) VALUES(?, ?)");839 ps.setInt(1, 3);840 ps.setInt(2, 495);841 assertEquals(1, ps.executeUpdate());842 ps.setInt(1, 4);843 assertEquals(1, ps.executeUpdate());844 ps.close();845 netConn.commit();846 ps = netConn.prepareStatement(847 "SELECT * FROM alltypes WHERE i = ?");848 ps.setInt(1, 495);849 rs = ps.executeQuery();850 assertTrue("Got no rows with i = 495", rs.next());851 assertEquals(Integer.class, rs.getObject("i").getClass());852 assertTrue("Got only one row with i = 495", rs.next());853 assertEquals(495, rs.getInt("i"));854 assertFalse("Got too many rows with i = 495", rs.next());855 } catch (SQLException se) {856 junit.framework.AssertionFailedError ase =857 new junit.framework.AssertionFailedError(se.getMessage());858 ase.initCause(se);859 throw ase;860 } finally {861 try {862 if (rs != null) {863 rs.close();864 }865 if (ps != null) {866 ps.close();867 }868 } catch (Exception ignored) {}869 }870 }871 @Test872 public void testTinyIntComplex() {873 PreparedStatement ps = null;874 ResultSet rs = null;875 try {876 ps = netConn.prepareStatement(877 "INSERT INTO alltypes(id, ti) VALUES(?, ?)");878 ps.setInt(1, 3);879 ps.setByte(2, (byte) 200);880 assertEquals(1, ps.executeUpdate());881 ps.setInt(1, 4);882 assertEquals(1, ps.executeUpdate());883 ps.close();884 netConn.commit();885 ps = netConn.prepareStatement(886 "SELECT * FROM alltypes WHERE ti = ?");887 ps.setByte(1, (byte) 200);888 rs = ps.executeQuery();889 assertTrue("Got no rows with ti = 200", rs.next());890 Object o = rs.getObject("ti"); // todo - returns string891 // assertEquals(Integer.class, o.getClass());892 assertTrue("Got only one row with ti = 200", rs.next());893 assertEquals((byte) 200, rs.getByte("ti"));894 assertFalse("Got too many rows with ti = 200", rs.next());895 assertFalse(false);896 } catch (SQLException se) {897 junit.framework.AssertionFailedError ase =898 new junit.framework.AssertionFailedError(se.getMessage());899 ase.initCause(se);900 throw ase;901 } finally {902 try {903 if (rs != null) {904 rs.close();905 }906 if (ps != null) {907 ps.close();908 }909 } catch (Exception ignored) {}910 }911 }912 @Test913 public void testSmallIntComplex() {914 PreparedStatement ps = null;915 ResultSet rs = null;916 try {917 ps = netConn.prepareStatement(918 "INSERT INTO alltypes(id, si) VALUES(?, ?)");919 ps.setInt(1, 3);920 ps.setShort(2, (short) 395);921 assertEquals(1, ps.executeUpdate());922 ps.setInt(1, 4);923 assertEquals(1, ps.executeUpdate());924 ps.close();925 netConn.commit();926 ps = netConn.prepareStatement(927 "SELECT * FROM alltypes WHERE si = ?");928 ps.setShort(1, (short) 395);929 rs = ps.executeQuery();930 assertTrue("Got no rows with si = 395", rs.next());931 assertEquals(Integer.class, rs.getObject("si").getClass());932 // Nb. HyperSQL purposefully returns an Integer for this type933 assertTrue("Got only one row with si = 395", rs.next());934 assertEquals((short) 395, rs.getShort("si"));935 assertFalse("Got too many rows with si = 395", rs.next());936 } catch (SQLException se) {937 junit.framework.AssertionFailedError ase =938 new junit.framework.AssertionFailedError(se.getMessage());939 ase.initCause(se);940 throw ase;941 } finally {942 try {943 if (rs != null) {944 rs.close();945 }946 if (ps != null) {947 ps.close();948 }949 } catch (Exception ignored) {}950 }951 }952 @Test953 public void testBigIntComplex() {954 PreparedStatement ps = null;955 ResultSet rs = null;956 try {957 ps = netConn.prepareStatement(958 "INSERT INTO alltypes(id, bi) VALUES(?, ?)");959 ps.setInt(1, 3);960 ps.setLong(2, 295L);961 assertEquals(1, ps.executeUpdate());962 ps.setInt(1, 4);963 assertEquals(1, ps.executeUpdate());964 ps.close();965 netConn.commit();966 ps = netConn.prepareStatement(967 "SELECT * FROM alltypes WHERE bi = ?");968 ps.setLong(1, 295L);969 rs = ps.executeQuery();970 assertTrue("Got no rows with bi = 295L", rs.next());971 assertEquals(Long.class, rs.getObject("bi").getClass());972 assertTrue("Got only one row with bi = 295L", rs.next());973 assertEquals(295L, rs.getLong("bi"));974 assertFalse("Got too many rows with bi = 295L", rs.next());975 } catch (SQLException se) {976 junit.framework.AssertionFailedError ase =977 new junit.framework.AssertionFailedError(se.getMessage());978 ase.initCause(se);979 throw ase;980 } finally {981 try {982 if (rs != null) {983 rs.close();984 }985 if (ps != null) {986 ps.close();987 }988 } catch (Exception ignored) {}989 }990 }991 /* TODO: Implement this test after get testNumericSimpleRead() working.992 * See that method above.993 public void testNumericComplex() {994 */995 @Test996 public void testFloatComplex() {997 PreparedStatement ps = null;998 ResultSet rs = null;999 try {1000 ps = netConn.prepareStatement(1001 "INSERT INTO alltypes(id, f) VALUES(?, ?)");1002 ps.setInt(1, 3);1003 ps.setFloat(2, 98.765F);1004 assertEquals(1, ps.executeUpdate());1005 ps.setInt(1, 4);1006 assertEquals(1, ps.executeUpdate());1007 ps.close();1008 netConn.commit();1009 ps = netConn.prepareStatement(1010 "SELECT * FROM alltypes WHERE f = ?");1011 ps.setFloat(1, 98.765F);1012 rs = ps.executeQuery();1013 assertTrue("Got no rows with f = 98.765F", rs.next());1014 assertEquals(Double.class, rs.getObject("f").getClass());1015 assertTrue("Got only one row with f = 98.765F", rs.next());1016 assertEquals(98.765D, rs.getDouble("f"), .01D);1017 assertFalse("Got too many rows with f = 98.765F", rs.next());1018 } catch (SQLException se) {1019 junit.framework.AssertionFailedError ase =1020 new junit.framework.AssertionFailedError(se.getMessage());1021 ase.initCause(se);1022 throw ase;1023 } finally {1024 try {1025 if (rs != null) {1026 rs.close();1027 }1028 if (ps != null) {1029 ps.close();1030 }1031 } catch (Exception ignored) {}1032 }1033 }1034 @Test1035 public void testDoubleComplex() {1036 PreparedStatement ps = null;1037 ResultSet rs = null;1038 try {1039 ps = netConn.prepareStatement(1040 "INSERT INTO alltypes(id, r) VALUES(?, ?)");1041 ps.setInt(1, 3);1042 ps.setDouble(2, 876.54D);1043 assertEquals(1, ps.executeUpdate());1044 ps.setInt(1, 4);1045 assertEquals(1, ps.executeUpdate());1046 ps.close();1047 netConn.commit();1048 ps = netConn.prepareStatement(1049 "SELECT * FROM alltypes WHERE r = ?");1050 ps.setDouble(1, 876.54D);1051 rs = ps.executeQuery();1052 assertTrue("Got no rows with r = 876.54D", rs.next());1053 assertEquals(Double.class, rs.getObject("r").getClass());1054 assertTrue("Got only one row with r = 876.54D", rs.next());1055 assertEquals(876.54D, rs.getDouble("r"), 0D);1056 assertFalse("Got too many rows with r = 876.54D", rs.next());1057 } catch (SQLException se) {1058 junit.framework.AssertionFailedError ase =1059 new junit.framework.AssertionFailedError(se.getMessage());1060 ase.initCause(se);1061 throw ase;1062 } finally {1063 try {1064 if (rs != null) {1065 rs.close();1066 }1067 if (ps != null) {1068 ps.close();1069 }1070 } catch (Exception ignored) {}1071 }1072 }1073 @Test1074 public void testBooleanComplex() {1075 PreparedStatement ps = null;1076 ResultSet rs = null;1077 try {1078 ps = netConn.prepareStatement(1079 "INSERT INTO alltypes(id, b) VALUES(?, ?)");1080 ps.setInt(1, 3);1081 ps.setBoolean(2, false);1082 assertEquals(1, ps.executeUpdate());1083 ps.setInt(1, 4);1084 assertEquals(1, ps.executeUpdate());1085 ps.close();1086 netConn.commit();1087 ps = netConn.prepareStatement(1088 "SELECT * FROM alltypes WHERE b = ?");1089 ps.setBoolean(1, false);1090 rs = ps.executeQuery();1091 assertTrue("Got no rows with b = false", rs.next());1092 Object o = rs.getObject("b"); // todo - returns string1093 // assertEquals(Boolean.class, rs.getObject("b").getClass());1094 assertTrue("Got only one row with b = false", rs.next());1095 assertEquals(false, rs.getBoolean("b"));1096 assertFalse("Got too many rows with b = false", rs.next());1097 } catch (SQLException se) {1098 junit.framework.AssertionFailedError ase =1099 new junit.framework.AssertionFailedError(se.getMessage());1100 ase.initCause(se);1101 throw ase;1102 } finally {1103 try {1104 if (rs != null) {1105 rs.close();1106 }1107 if (ps != null) {1108 ps.close();1109 }1110 } catch (Exception ignored) {}1111 }1112 }1113 @Test1114 public void testCharComplex() {1115 PreparedStatement ps = null;1116 ResultSet rs = null;1117 try {1118 ps = netConn.prepareStatement(1119 "INSERT INTO alltypes(id, c) VALUES(?, ?)");1120 ps.setInt(1, 3);1121 ps.setString(2, "xy");1122 assertEquals(1, ps.executeUpdate());1123 ps.setInt(1, 4);1124 assertEquals(1, ps.executeUpdate());1125 ps.close();1126 netConn.commit();1127 ps = netConn.prepareStatement(1128 "SELECT * FROM alltypes WHERE c = ?");1129 ps.setString(1, "xy ");1130 rs = ps.executeQuery();1131 assertTrue("Got no rows with c = 'xy '", rs.next());1132 assertEquals(String.class, rs.getObject("c").getClass());1133 assertTrue("Got only one row with c = 'xy '", rs.next());1134 assertEquals("xy ", rs.getString("c"));1135 assertFalse("Got too many rows with c = 'xy '", rs.next());1136 } catch (SQLException se) {1137 junit.framework.AssertionFailedError ase =1138 new junit.framework.AssertionFailedError(se.getMessage());1139 ase.initCause(se);1140 throw ase;1141 } finally {1142 try {1143 if (rs != null) {1144 rs.close();1145 }1146 if (ps != null) {1147 ps.close();1148 }1149 } catch (Exception ignored) {}1150 }1151 }1152 @Test1153 public void testVarCharComplex() {1154 PreparedStatement ps = null;1155 ResultSet rs = null;1156 try {1157 ps = netConn.prepareStatement(1158 "INSERT INTO alltypes(id, cv) VALUES(?, ?)");1159 ps.setInt(1, 3);1160 ps.setString(2, "xy");1161 assertEquals(1, ps.executeUpdate());1162 ps.setInt(1, 4);1163 assertEquals(1, ps.executeUpdate());1164 ps.close();1165 netConn.commit();1166 ps = netConn.prepareStatement(1167 "SELECT * FROM alltypes WHERE cv = ?");1168 ps.setString(1, "xy");1169 rs = ps.executeQuery();1170 assertTrue("Got no rows with cv = 'xy'", rs.next());1171 assertEquals(String.class, rs.getObject("cv").getClass());1172 assertTrue("Got only one row with cv = 'xy'", rs.next());1173 assertEquals("xy", rs.getString("cv"));1174 assertFalse("Got too many rows with cv = 'xy'", rs.next());1175 } catch (SQLException se) {1176 junit.framework.AssertionFailedError ase =1177 new junit.framework.AssertionFailedError(se.getMessage());1178 ase.initCause(se);1179 throw ase;1180 } finally {1181 try {1182 if (rs != null) {1183 rs.close();1184 }1185 if (ps != null) {1186 ps.close();1187 }1188 } catch (Exception ignored) {}1189 }1190 }1191 /**1192 * TODO: Find out if there is a way to select based on an expression1193 * using a named derived pseudo-column.1194 */1195 @Test1196 public void testDerivedComplex() {1197 PreparedStatement ps = null;1198 ResultSet rs = null;1199 try {1200 ps = netConn.prepareStatement(1201 "SELECT id, cv || 'app' appendage FROM alltypes\n"1202 + "WHERE (cv || 'app') = ?");1203 ps.setString(1, "cvapp");1204 rs = ps.executeQuery();1205 assertTrue("Got no rows appendage = 'cvapp'", rs.next());1206 assertEquals(String.class, rs.getObject("r").getClass());1207 assertTrue("Got only one row with appendage = 'cvapp'", rs.next());1208 assertEquals("cvapp", rs.getString("r"));1209 assertFalse("Got too many rows with appendage = 'cvapp'", rs.next());1210 } catch (SQLException se) {1211 junit.framework.AssertionFailedError ase1212 = new junit.framework.AssertionFailedError(se.getMessage());1213 ase.initCause(se);1214 throw ase;1215 } finally {1216 try {1217 if (rs != null) {1218 rs.close();1219 }1220 if (ps != null) {1221 ps.close();1222 }1223 } catch(Exception ignored) {1224 }1225 }1226 }1227 @Test1228 public void testDateComplex() {1229 PreparedStatement ps = null;1230 ResultSet rs = null;1231 java.sql.Date tomorrow =1232 new java.sql.Date(new java.util.Date().getTime()1233 + 1000 * 60 * 60 * 24);1234 try {1235 ps = netConn.prepareStatement(1236 "INSERT INTO alltypes(id, d) VALUES(?, ?)");1237 ps.setInt(1, 3);1238 ps.setDate(2, tomorrow);1239 assertEquals(1, ps.executeUpdate());1240 ps.setInt(1, 4);1241 assertEquals(1, ps.executeUpdate());1242 ps.close();1243 netConn.commit();1244 ps = netConn.prepareStatement(1245 "SELECT * FROM alltypes WHERE d = ?");1246 ps.setDate(1, tomorrow);1247 rs = ps.executeQuery();1248 assertTrue("Got no rows with d = tomorrow", rs.next());1249 assertEquals(java.sql.Date.class, rs.getObject("d").getClass());1250 assertTrue("Got only one row with d = tomorrow", rs.next());1251 assertEquals(tomorrow.toString(), rs.getDate("d").toString());1252 // Compare the Strings since "tomorrow" has resolution to1253 // millisecond, but getDate() is probably to the day.1254 assertFalse("Got too many rows with d = tomorrow", rs.next());1255 } catch (SQLException se) {1256 junit.framework.AssertionFailedError ase =1257 new junit.framework.AssertionFailedError(se.getMessage());1258 ase.initCause(se);1259 throw ase;1260 } finally {1261 try {1262 if (rs != null) {1263 rs.close();1264 }1265 if (ps != null) {1266 ps.close();1267 }1268 } catch (Exception ignored) {}1269 }1270 }1271 @Test1272 public void testTimeComplex() {1273 PreparedStatement ps = null;1274 ResultSet rs = null;1275 Time aTime = Time.valueOf("21:19:27");1276 try {1277 ps = netConn.prepareStatement(1278 "INSERT INTO alltypes(id, t) VALUES(?, ?)");1279 ps.setInt(1, 3);1280 ps.setTime(2, aTime);1281 assertEquals(1, ps.executeUpdate());1282 ps.setInt(1, 4);1283 assertEquals(1, ps.executeUpdate());1284 ps.close();1285 netConn.commit();1286 ps = netConn.prepareStatement(1287 "SELECT * FROM alltypes WHERE t = ?");1288 ps.setTime(1, aTime);1289 rs = ps.executeQuery();1290 assertTrue("Got no rows with t = aTime", rs.next());1291 assertEquals(Time.class, rs.getObject("t").getClass());1292 assertTrue("Got only one row with t = aTime", rs.next());1293 assertEquals(aTime, rs.getTime("t"));1294 assertFalse("Got too many rows with t = aTime", rs.next());1295 } catch (SQLException se) {1296 junit.framework.AssertionFailedError ase =1297 new junit.framework.AssertionFailedError(se.getMessage());1298 ase.initCause(se);1299 throw ase;1300 } finally {1301 try {1302 if (rs != null) {1303 rs.close();1304 }1305 if (ps != null) {1306 ps.close();1307 }1308 } catch (Exception ignored) {}1309 }1310 }1311 /* TODO: Implement this test after get testTimeWSimpleRead() working.1312 * See that method above.1313 public void testTimeWComplex() {1314 */1315 @Test1316 public void testTimestampComplex() {1317 PreparedStatement ps = null;1318 ResultSet rs = null;1319 Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1320 try {1321 ps = netConn.prepareStatement(1322 "INSERT INTO alltypes(id, ts) VALUES(?, ?)");1323 ps.setInt(1, 3);1324 ps.setTimestamp(2, aTimestamp);1325 assertEquals(1, ps.executeUpdate());1326 ps.setInt(1, 4);1327 assertEquals(1, ps.executeUpdate());1328 ps.close();1329 netConn.commit();1330 ps = netConn.prepareStatement(1331 "SELECT * FROM alltypes WHERE ts = ?");1332 ps.setTimestamp(1, aTimestamp);1333 rs = ps.executeQuery();1334 assertTrue("Got no rows with ts = aTimestamp", rs.next());1335 assertEquals(Timestamp.class, rs.getObject("ts").getClass());1336 assertTrue("Got only one row with ts = aTimestamp", rs.next());1337 assertEquals(aTimestamp, rs.getTimestamp("ts"));1338 assertFalse("Got too many rows with ts = aTimestamp", rs.next());1339 } catch (SQLException se) {1340 junit.framework.AssertionFailedError ase =1341 new junit.framework.AssertionFailedError(se.getMessage());1342 ase.initCause(se);1343 throw ase;1344 } finally {1345 try {1346 if (rs != null) {1347 rs.close();1348 }1349 if (ps != null) {1350 ps.close();1351 }1352 } catch (Exception ignored) {}1353 }1354 }1355 @Test1356 public void testTimestampWComplex() {1357 PreparedStatement ps = null;1358 ResultSet rs = null;1359 Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1360 try {1361 ps = netConn.prepareStatement(1362 "INSERT INTO alltypes(id, tsw) VALUES(?, ?)");1363 ps.setInt(1, 3);1364 ps.setTimestamp(2, aTimestamp);1365 assertEquals(1, ps.executeUpdate());1366 ps.setInt(1, 4);1367 assertEquals(1, ps.executeUpdate());1368 ps.close();1369 netConn.commit();1370 ps = netConn.prepareStatement(1371 "SELECT * FROM alltypes WHERE tsw = ?");1372 ps.setTimestamp(1, aTimestamp);1373 rs = ps.executeQuery();1374 assertTrue("Got no rows with tsw = aTimestamp", rs.next());1375 assertEquals(Timestamp.class, rs.getObject("tsw").getClass());1376 assertTrue("Got only one row with tsw = aTimestamp", rs.next());1377 assertEquals(aTimestamp, rs.getTimestamp("tsw"));1378 assertFalse("Got too many rows with tsw = aTimestamp", rs.next());1379 } catch (SQLException se) {1380 junit.framework.AssertionFailedError ase =1381 new junit.framework.AssertionFailedError(se.getMessage());1382 ase.initCause(se);1383 throw ase;1384 } finally {1385 try {1386 if (rs != null) {1387 rs.close();1388 }1389 if (ps != null) {1390 ps.close();1391 }1392 } catch (Exception ignored) {}1393 }1394 }1395 /*1396 * Driver needs to be modified to transfer bits in byte (binary) fashion,1397 * the same as is done for VARBINARY/bytea type.1398 */1399 @Ignore1400 public void testBitComplex() {1401 PreparedStatement ps = null;1402 ResultSet rs = null;1403 try {1404 ps = netConn.prepareStatement(1405 "INSERT INTO alltypes(id, bt) VALUES(?, ?)");1406 ps.setInt(1, 3);1407 ps.setString(2, "101");1408 assertEquals(1, ps.executeUpdate());1409 ps.setInt(1, 4);1410 assertEquals(1, ps.executeUpdate());1411 ps.close();1412 netConn.commit();1413 ps = netConn.prepareStatement(1414 "SELECT * FROM alltypes WHERE bt = ?");1415 ps.setString(1, "101");1416 rs = ps.executeQuery();1417 assertTrue("Got no rows with bt = 101", rs.next());1418 assertEquals(String.class, rs.getObject("bt").getClass());1419 assertTrue("Got only one row with bt = 101", rs.next());1420 assertEquals("101000000", rs.getString("bt"));1421 assertFalse("Got too many rows with bt = 101", rs.next());1422 } catch (SQLException se) {1423 junit.framework.AssertionFailedError ase1424 = new junit.framework.AssertionFailedError(se.getMessage());1425 ase.initCause(se);1426 throw ase;1427 } finally {1428 try {1429 if (rs != null) {1430 rs.close();1431 }1432 if (ps != null) {1433 ps.close();1434 }1435 } catch(Exception ignored) {1436 } }1437 }1438 @Ignore1439 public void testBitVaryingComplex() {1440 PreparedStatement ps = null;1441 ResultSet rs = null;1442 try {1443 ps = netConn.prepareStatement(1444 "INSERT INTO alltypes(id, btv) VALUES(?, ?)");1445 ps.setInt(1, 3);1446 ps.setString(2, "10101"); // toto - throws right truncation1447 assertEquals(1, ps.executeUpdate());1448 ps.setInt(1, 4);1449 assertEquals(1, ps.executeUpdate());1450 ps.close();1451 netConn.commit();1452 ps = netConn.prepareStatement(1453 "SELECT * FROM alltypes WHERE btv = ?");1454 ps.setString(1, "10101");1455 rs = ps.executeQuery();1456 assertTrue("Got no rows with btv = 10101", rs.next());1457 Object o = rs.getObject("btv");1458 assertEquals(String.class, rs.getObject("btv").getClass());1459 assertTrue("Got only one row with btv = 10101", rs.next());1460 assertEquals("10101", rs.getString("btv"));1461 assertFalse("Got too many rows with btv = 10101", rs.next());1462 } catch (SQLException se) {1463 junit.framework.AssertionFailedError ase1464 = new junit.framework.AssertionFailedError(se.getMessage());1465 ase.initCause(se);1466 throw ase;1467 } finally {1468 try {1469 if (rs != null) {1470 rs.close();1471 }1472 if (ps != null) {1473 ps.close();1474 }1475 } catch(Exception ignored) {1476 }1477 }1478 }1479 @Test1480 public void testBinaryComplex() {1481 PreparedStatement ps = null;1482 ResultSet rs = null;1483 byte[] expectedBytes = new byte[] {1484 (byte) 0xaa, (byte) 0x99, (byte) 0, (byte) 01485 };1486 byte[] ba1, ba2;1487 try {1488 ps = netConn.prepareStatement(1489 "INSERT INTO alltypes(id, bin) VALUES(?, ?)");1490 ps.setInt(1, 3);1491 ps.setBytes(2, expectedBytes);1492 assertEquals(1, ps.executeUpdate());1493 ps.setInt(1, 4);1494 assertEquals(1, ps.executeUpdate());1495 ps.close();1496 netConn.commit();1497 ps = netConn.prepareStatement(1498 "SELECT * FROM alltypes WHERE bin = ?");1499 ps.setBytes(1, expectedBytes);1500 rs = ps.executeQuery();1501 assertTrue("Got no rows with bin = b'AA99'", rs.next());1502 ba1 = rs.getBytes("bin");1503 assertTrue("Got only one row with bin = b'AA99'", rs.next());1504 ba2 = rs.getBytes("bin");1505 assertFalse("Got too many rows with bin = b'AA99'", rs.next());1506 } catch (SQLException se) {1507 junit.framework.AssertionFailedError ase =1508 new junit.framework.AssertionFailedError(se.getMessage());1509 ase.initCause(se);1510 throw ase;1511 } finally {1512 try {1513 if (rs != null) {1514 rs.close();1515 }1516 if (ps != null) {1517 ps.close();1518 }1519 } catch (Exception ignored) {}1520 }1521 assertEquals("Retrieved bye array length wrong (1)",1522 expectedBytes.length, ba1.length);1523 for (int i = 0; i < ba1.length; i++) {1524 assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1525 }1526 assertEquals("Retrieved bye array length wrong (2)",1527 expectedBytes.length, ba2.length);1528 for (int i = 0; i < ba2.length; i++) {1529 assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1530 }1531 }1532 @Test1533 public void testVarBinaryComplex() {1534 PreparedStatement ps = null;1535 ResultSet rs = null;1536 byte[] expectedBytes = new byte[] {1537 (byte) 0xaa, (byte) 0x991538 };1539 byte[] ba1, ba2;1540 try {1541 ps = netConn.prepareStatement(1542 "INSERT INTO alltypes(id, vb) VALUES(?, ?)");1543 ps.setInt(1, 3);1544 ps.setBytes(2, expectedBytes);1545 assertEquals(1, ps.executeUpdate());1546 ps.setInt(1, 4);1547 assertEquals(1, ps.executeUpdate());1548 ps.close();1549 netConn.commit();1550 ps = netConn.prepareStatement(1551 "SELECT * FROM alltypes WHERE vb = ?");1552 ps.setBytes(1, expectedBytes);1553 rs = ps.executeQuery();1554 assertTrue("Got no rows with vb = b'AA99'", rs.next());1555 ba1 = rs.getBytes("vb");1556 assertTrue("Got only one row with vb = b'AA99'", rs.next());1557 ba2 = rs.getBytes("vb");1558 assertFalse("Got too many rows with vb = b'AA99'", rs.next());1559 } catch (SQLException se) {1560 junit.framework.AssertionFailedError ase =1561 new junit.framework.AssertionFailedError(se.getMessage());1562 ase.initCause(se);1563 throw ase;1564 } finally {1565 try {1566 if (rs != null) {1567 rs.close();1568 }1569 if (ps != null) {1570 ps.close();1571 }1572 } catch (Exception ignored) {}1573 }1574 assertEquals("Retrieved bye array length wrong (1)",1575 expectedBytes.length, ba1.length);1576 for (int i = 0; i < ba1.length; i++) {1577 assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1578 }1579 assertEquals("Retrieved bye array length wrong (2)",1580 expectedBytes.length, ba2.length);1581 for (int i = 0; i < ba2.length; i++) {1582 assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1583 }1584 }1585 /*1586 * TODO: Learn how to set input params for INTERVAL types.1587 * I don't see how I could set the variant1588 * (HOUR, ...TO SECOND, etc.) with setString() or anything else.1589 */1590 @Test1591 public void testDaySecIntervalComplex() {1592 PreparedStatement ps = null;1593 ResultSet rs = null;1594 try {1595 ps = netConn.prepareStatement(1596 "INSERT INTO alltypes(id, dsival) VALUES(?, ?)");1597 ps.setInt(1, 3);1598 ps.setString(2, "45 23:12:19.345000");1599 assertEquals(1, ps.executeUpdate());1600 ps.setInt(1, 4);1601 assertEquals(1, ps.executeUpdate());1602 ps.close();1603 netConn.commit();1604 ps = netConn.prepareStatement(1605 "SELECT * FROM alltypes WHERE dsival = ?");1606 ps.setString(1, "45 23:12:19.345000");1607 rs = ps.executeQuery();1608 assertTrue("Got no rows with dsival = 45 23:12:19.345000", rs.next());1609 assertEquals(String.class, rs.getObject("dsival").getClass());1610 assertTrue("Got only one row with dsival = 45 23:12:19.345000", rs.next());1611 assertEquals("45 23:12:19.345000", rs.getString("dsival"));1612 assertFalse("Got too many rows with dsival = 45 23:12:19.345000", rs.next());1613 } catch (SQLException se) {1614 junit.framework.AssertionFailedError ase1615 = new junit.framework.AssertionFailedError(se.getMessage());1616 ase.initCause(se);1617 throw ase;1618 } finally {1619 try {1620 if (rs != null) {1621 rs.close();1622 }1623 if (ps != null) {1624 ps.close();1625 }1626 } catch(Exception e) {1627 }1628 }1629 }1630 @Test1631 public void testSecIntervalComplex() {1632 PreparedStatement ps = null;1633 ResultSet rs = null;1634 try {1635 ps = netConn.prepareStatement(1636 "INSERT INTO alltypes(id, sival) VALUES(?, ?)");1637 ps.setInt(1, 3);1638 ps.setString(2, "876.54");1639 assertEquals(1, ps.executeUpdate());1640 ps.setInt(1, 4);1641 assertEquals(1, ps.executeUpdate());1642 ps.close();1643 netConn.commit();1644 ps = netConn.prepareStatement(1645 "SELECT * FROM alltypes WHERE sival = ?");1646 ps.setString(1, "876.54");1647 rs = ps.executeQuery();1648 assertTrue("Got no rows with sival = 876.54D", rs.next());1649 assertEquals(String.class, rs.getObject("sival").getClass());1650 assertTrue("Got only one row with sival = 876.54D", rs.next());1651 assertTrue(rs.getString("sival").startsWith("876.54"));1652 assertFalse("Got too many rows with sival = 876.54D", rs.next());1653 } catch (SQLException se) {1654 junit.framework.AssertionFailedError ase1655 = new junit.framework.AssertionFailedError(se.getMessage());1656 ase.initCause(se);1657 throw ase;1658 } finally {1659 try {1660 if (rs != null) {1661 rs.close();1662 }1663 if (ps != null) {1664 ps.close();1665 }1666 } catch(Exception e) {...

Full Screen

Full Screen

Source:MultivariateSummaryStatisticsTest.java Github

copy

Full Screen

...156 junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getMin()[0]));157 junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getStandardDeviation()[0]));158 junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getGeometricMean()[0]));159 u.addValue(new double[]{ 1.0 });160 junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getMean()[0]));161 junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getMin()[0]));162 junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getStandardDeviation()[0]));163 junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getGeometricMean()[0]));164 }165 public void testSerialization() throws org.apache.commons.math.DimensionMismatchException {166 org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);167 org.apache.commons.math.TestUtils.checkSerializedEquality(u);168 org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics s = ((org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));169 junit.framework.Assert.assertEquals(u, s);170 u.addValue(new double[]{ 2.0 , 1.0 });171 u.addValue(new double[]{ 1.0 , 1.0 });172 u.addValue(new double[]{ 3.0 , 1.0 });173 u.addValue(new double[]{ 4.0 , 1.0 });174 u.addValue(new double[]{ 5.0 , 1.0 });175 org.apache.commons.math.TestUtils.checkSerializedEquality(u);176 s = ((org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));177 junit.framework.Assert.assertEquals(u, s);178 }179 public void testEqualsAndHashCode() throws org.apache.commons.math.DimensionMismatchException {180 org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);181 org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics t = null;182 int emptyHash = u.hashCode();183 junit.framework.Assert.assertTrue(u.equals(u));184 junit.framework.Assert.assertFalse(u.equals(t));185 junit.framework.Assert.assertFalse(u.equals(java.lang.Double.valueOf(0)));186 t = createMultivariateSummaryStatistics(2, true);187 junit.framework.Assert.assertTrue(t.equals(u));188 junit.framework.Assert.assertTrue(u.equals(t));189 junit.framework.Assert.assertEquals(emptyHash, t.hashCode());190 u.addValue(new double[]{ 2.0 , 1.0 });191 u.addValue(new double[]{ 1.0 , 1.0 });192 u.addValue(new double[]{ 3.0 , 1.0 });193 u.addValue(new double[]{ 4.0 , 1.0 });194 u.addValue(new double[]{ 5.0 , 1.0 });195 junit.framework.Assert.assertFalse(t.equals(u));196 junit.framework.Assert.assertFalse(u.equals(t));197 junit.framework.Assert.assertTrue(((u.hashCode()) != (t.hashCode())));198 t.addValue(new double[]{ 2.0 , 1.0 });199 t.addValue(new double[]{ 1.0 , 1.0 });200 t.addValue(new double[]{ 3.0 , 1.0 });201 t.addValue(new double[]{ 4.0 , 1.0 });202 t.addValue(new double[]{ 5.0 , 1.0 });203 junit.framework.Assert.assertTrue(t.equals(u));204 junit.framework.Assert.assertTrue(u.equals(t));205 junit.framework.Assert.assertEquals(u.hashCode(), t.hashCode());206 u.clear();207 t.clear();208 junit.framework.Assert.assertTrue(t.equals(u));209 junit.framework.Assert.assertTrue(u.equals(t));210 junit.framework.Assert.assertEquals(emptyHash, t.hashCode());...

Full Screen

Full Screen

Source:FunctionEvaluationExceptionTest.java Github

copy

Full Screen

...25 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);26 for (int i = 0 ; i < (arguments.length) ; ++i) {27 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);28 }29 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));30 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));31 }32 public void testConstructorArrayPatternArguments() {33 java.lang.String pattern = "evaluation failed for argument = {0}";34 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Double.valueOf(0.0) };35 org.apache.commons.math.FunctionEvaluationException ex = new org.apache.commons.math.FunctionEvaluationException(new double[]{ 0 , 1 , 2 } , pattern , arguments);36 junit.framework.Assert.assertNull(ex.getCause());37 junit.framework.Assert.assertEquals(pattern, ex.getPattern());38 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);39 for (int i = 0 ; i < (arguments.length) ; ++i) {40 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);41 }42 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));43 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));44 junit.framework.Assert.assertEquals(0.0, ex.getArgument()[0], 0);45 junit.framework.Assert.assertEquals(1.0, ex.getArgument()[1], 0);46 junit.framework.Assert.assertEquals(2.0, ex.getArgument()[2], 0);47 }48 public void testConstructorPatternArgumentsCause() {49 java.lang.String pattern = "evaluation failed for argument = {0}";50 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Double.valueOf(0.0) };51 java.lang.String inMsg = "inner message";52 java.lang.Exception cause = new java.lang.Exception(inMsg);53 org.apache.commons.math.FunctionEvaluationException ex = new org.apache.commons.math.FunctionEvaluationException(cause , 0.0 , pattern , arguments);54 junit.framework.Assert.assertEquals(cause, ex.getCause());55 junit.framework.Assert.assertEquals(pattern, ex.getPattern());56 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);57 for (int i = 0 ; i < (arguments.length) ; ++i) {58 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);59 }60 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));61 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));62 }63 public void testConstructorArrayPatternArgumentsCause() {64 java.lang.String pattern = "evaluation failed for argument = {0}";65 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Double.valueOf(0.0) };66 java.lang.String inMsg = "inner message";67 java.lang.Exception cause = new java.lang.Exception(inMsg);68 org.apache.commons.math.FunctionEvaluationException ex = new org.apache.commons.math.FunctionEvaluationException(cause , new double[]{ 0 , 1 , 2 } , pattern , arguments);69 junit.framework.Assert.assertEquals(cause, ex.getCause());70 junit.framework.Assert.assertEquals(pattern, ex.getPattern());71 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);72 for (int i = 0 ; i < (arguments.length) ; ++i) {73 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);74 }75 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));76 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));77 junit.framework.Assert.assertEquals(0.0, ex.getArgument()[0], 0);78 junit.framework.Assert.assertEquals(1.0, ex.getArgument()[1], 0);79 junit.framework.Assert.assertEquals(2.0, ex.getArgument()[2], 0);80 }81 public void testConstructorArgumentCause() {82 java.lang.String inMsg = "inner message";83 java.lang.Exception cause = new java.lang.Exception(inMsg);84 org.apache.commons.math.FunctionEvaluationException ex = new org.apache.commons.math.FunctionEvaluationException(cause , 0.0);85 junit.framework.Assert.assertEquals(cause, ex.getCause());86 junit.framework.Assert.assertTrue(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));87 }88 public void testConstructorArrayArgumentCause() {89 java.lang.String inMsg = "inner message";90 java.lang.Exception cause = new java.lang.Exception(inMsg);...

Full Screen

Full Screen

Source:AssertTrueInsteadOfDedicatedAssertCheckTest.java Github

copy

Full Screen

...20package checks;21import junit.framework.TestCase;22import org.junit.Assert;23import org.junit.jupiter.api.Assertions;24import static org.junit.Assert.assertFalse;25import static org.junit.Assert.assertTrue;26public class AssertTrueInsteadOfDedicatedAssertCheckTest {27 Object foo = null;28 Object bar = null;29 boolean predicate() {30 return true;31 }32 {33 assertTrue(null == null); // Noncompliant34 Assertions.assertFalse(null == null); // Noncompliant35 }36 void assertTrue_JUnit4_orgJunitAssert() {37 Assert.assertTrue(null == foo); // Noncompliant [[sc=12;ec=22;secondary=44]] {{Use assertNull instead.}}38 assertTrue(foo == null); // Noncompliant39 Assert.assertTrue(foo != null); // Noncompliant {{Use assertNotNull instead.}}40 assertTrue("null and foo should not be equal", null != foo); // Noncompliant41 Assert.assertTrue(foo == bar); // Noncompliant {{Use assertSame instead.}}42 assertTrue(bar != foo); // Noncompliant {{Use assertNotSame instead.}}43 Assert.assertTrue("This is a String", foo.equals(bar)); // Noncompliant {{Use assertEquals instead.}}44 assertTrue(!bar.equals(foo)); // Noncompliant {{Use assertNotEquals instead.}}45 assertTrue((foo = bar).equals(bar)); // Noncompliant {{Use assertEquals instead.}}46 Assert.assertTrue(foo == null || foo == null); // compliant - we only flag simple cases47 assertTrue(predicate()); // compliant48 assertTrue(foo.equals(bar) && bar != null); // compliant49 }50 void assertFalse_JUnit4_orgJunitAssert() {51 Assert.assertFalse(null == foo); // Noncompliant {{Use assertNotNull instead.}}52 assertFalse(foo == null); // Noncompliant53 Assert.assertFalse(foo != null); // Noncompliant {{Use assertNull instead.}}54 assertFalse("null and foo should not be equal", null != foo); // Noncompliant55 Assert.assertFalse(foo == bar); // Noncompliant {{Use assertNotSame instead.}}56 assertFalse(bar != foo); // Noncompliant {{Use assertSame instead.}}57 Assert.assertFalse("This is a String", foo.equals(bar)); // Noncompliant {{Use assertNotEquals instead.}}58 assertFalse(!bar.equals(foo)); // Noncompliant {{Use assertEquals instead.}}59 assertFalse((foo = bar).equals(bar)); // Noncompliant {{Use assertNotEquals instead.}}60 Assert.assertFalse(foo == null || foo == null); // compliant - we only flag simple cases61 assertFalse(predicate()); // compliant62 assertFalse(foo.equals(bar) && bar != null); // compliant63 }64 class MyTestCase extends TestCase {65 void assertTrueFalse_JUnit4_junitFrameworkTestCase() {66 super.assertTrue(null == foo); // Noncompliant67 assertTrue("message", foo == bar); // Noncompliant68 assertFalse(foo == null); // Noncompliant69 assertFalse(null != bar); // Noncompliant70 assertTrue(predicate()); // compliant71 }72 }73 void assertTrueFalse_JUnit4_junitFrameworkAssert() {74 junit.framework.Assert.assertTrue(foo != bar); // Noncompliant75 junit.framework.Assert.assertTrue("message", bar != null); // Noncompliant76 junit.framework.Assert.assertFalse(bar == foo); // Noncompliant77 junit.framework.Assert.assertFalse("message", null != foo); // Noncompliant78 }79 void assertTrueFalse_JUnit5() {80 Assertions.assertTrue(foo != bar); // Noncompliant81 Assertions.assertTrue(bar != null, "mhmm a massage!"); // Noncompliant82 Assertions.assertTrue(bar != null, () -> "a lazy massage :/"); // Noncompliant83 Assertions.assertFalse(bar == foo); // Noncompliant84 Assertions.assertFalse(null != foo, "message"); // Noncompliant85 Assertions.assertFalse(null != foo, () -> "message"); // Noncompliant86 Assertions.assertTrue(() -> foo == bar); // false-negative because BooleanSupplier is not supported by this rule87 }88 void testPrimitiveAndBoxedTypesSpecialCases() {89 assertFalse(2 == 3); // Noncompliant {{Use assertNotEquals instead.}}90 assertTrue(new Integer(5) == 6); // Noncompliant {{Use assertEquals instead.}}91 assertTrue(Boolean.valueOf(true) != false); // Noncompliant {{Use assertNotEquals instead.}}92 assertTrue(new Integer(5) == new Integer(5)); // Noncompliant {{Use assertSame instead.}}93 }94}...

Full Screen

Full Screen

Source:SuiteMethodTest.java Github

copy

Full Screen

1package org.junit.tests.junit3compatibility;23import static org.junit.Assert.assertEquals;4import static org.junit.Assert.assertFalse;5import static org.junit.Assert.assertTrue;6import static org.junit.Assert.fail;7import junit.framework.JUnit4TestAdapter;8import junit.framework.TestCase;9import junit.framework.TestSuite;10import org.junit.Ignore;11import org.junit.Test;12import org.junit.runner.Description;13import org.junit.runner.JUnitCore;14import org.junit.runner.Request;15import org.junit.runner.Result;1617public class SuiteMethodTest {18 public static boolean wasRun;1920 static public class OldTest extends TestCase {21 public OldTest(String name) {22 super(name);23 }24 25 public static junit.framework.Test suite() {26 TestSuite result= new TestSuite();27 result.addTest(new OldTest("notObviouslyATest"));28 return result;29 }30 31 public void notObviouslyATest() {32 wasRun= true;33 }34 }35 36 @Test public void makeSureSuiteIsCalled() {37 wasRun= false;38 JUnitCore.runClasses(OldTest.class);39 assertTrue(wasRun);40 }41 42 static public class NewTest {43 @Test public void sample() {44 wasRun= true;45 }4647 public static junit.framework.Test suite() {48 return new JUnit4TestAdapter(NewTest.class);49 }50 }51 52 @Test public void makeSureSuiteWorksWithJUnit4Classes() {53 wasRun= false;54 JUnitCore.runClasses(NewTest.class);55 assertTrue(wasRun);56 }57 5859 public static class CompatibilityTest {60 @Ignore @Test61 public void ignored() {62 }63 64 public static junit.framework.Test suite() {65 return new JUnit4TestAdapter(CompatibilityTest.class);66 }67 }68 69 @Test public void descriptionAndRunNotificationsAreConsistent() {70 Result result= JUnitCore.runClasses(CompatibilityTest.class);71 assertEquals(0, result.getIgnoreCount());72 73 Description description= Request.aClass(CompatibilityTest.class).getRunner().getDescription();74 assertEquals(0, description.getChildren().size());75 }76 77 static public class NewTestSuiteFails {78 @Test public void sample() {79 wasRun= true;80 }81 82 public static junit.framework.Test suite() {83 fail("called with JUnit 4 runner");84 return null;85 }86 }87 88 @Test public void suiteIsUsedWithJUnit4Classes() {89 wasRun= false;90 Result result= JUnitCore.runClasses(NewTestSuiteFails.class);91 assertEquals(1, result.getFailureCount());92 assertFalse(wasRun);93 }94 95 static public class NewTestSuiteNotUsed {96 private static boolean wasIgnoredRun;97 98 @Test public void sample() {99 wasRun= true;100 }101 102 @Ignore @Test public void ignore() {103 wasIgnoredRun= true;104 }105 106 public static junit.framework.Test suite() {107 return new JUnit4TestAdapter(NewTestSuiteNotUsed.class);108 }109 }110 111 @Test public void makeSureSuiteNotUsedWithJUnit4Classes2() {112 wasRun= false;113 NewTestSuiteNotUsed.wasIgnoredRun= false;114 Result res= JUnitCore.runClasses(NewTestSuiteNotUsed.class);115 assertTrue(wasRun);116 assertFalse(NewTestSuiteNotUsed.wasIgnoredRun);117 assertEquals(0, res.getFailureCount());118 assertEquals(1, res.getRunCount());119 assertEquals(0, res.getIgnoreCount());120 }121} ...

Full Screen

Full Screen

Source:ConvergenceExceptionTest.java Github

copy

Full Screen

...4 org.apache.commons.math.ConvergenceException ex = new org.apache.commons.math.ConvergenceException();5 junit.framework.Assert.assertNull(ex.getCause());6 junit.framework.Assert.assertNotNull(ex.getMessage());7 junit.framework.Assert.assertNotNull(ex.getMessage(java.util.Locale.FRENCH));8 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));9 }10 public void testConstructorPatternArguments() {11 java.lang.String pattern = "a {0}x{1} matrix cannot be a rotation matrix";12 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Integer.valueOf(6) , java.lang.Integer.valueOf(4) };13 org.apache.commons.math.ConvergenceException ex = new org.apache.commons.math.ConvergenceException(pattern , arguments);14 junit.framework.Assert.assertNull(ex.getCause());15 junit.framework.Assert.assertEquals(pattern, ex.getPattern());16 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);17 for (int i = 0 ; i < (arguments.length) ; ++i) {18 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);19 }20 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));21 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));22 }23 public void testConstructorCause() {24 java.lang.String inMsg = "inner message";25 java.lang.Exception cause = new java.lang.Exception(inMsg);26 org.apache.commons.math.ConvergenceException ex = new org.apache.commons.math.ConvergenceException(cause);27 junit.framework.Assert.assertEquals(cause, ex.getCause());28 }29 public void testConstructorPatternArgumentsCause() {30 java.lang.String pattern = "a {0}x{1} matrix cannot be a rotation matrix";31 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Integer.valueOf(6) , java.lang.Integer.valueOf(4) };32 java.lang.String inMsg = "inner message";33 java.lang.Exception cause = new java.lang.Exception(inMsg);34 org.apache.commons.math.ConvergenceException ex = new org.apache.commons.math.ConvergenceException(cause , pattern , arguments);35 junit.framework.Assert.assertEquals(cause, ex.getCause());36 junit.framework.Assert.assertEquals(pattern, ex.getPattern());37 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);38 for (int i = 0 ; i < (arguments.length) ; ++i) {39 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);40 }41 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));42 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));43 }44}...

Full Screen

Full Screen

Source:MathConfigurationExceptionTest.java Github

copy

Full Screen

...15 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);16 for (int i = 0 ; i < (arguments.length) ; ++i) {17 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);18 }19 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));20 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));21 }22 public void testConstructorCause() {23 java.lang.String inMsg = "inner message";24 java.lang.Exception cause = new java.lang.Exception(inMsg);25 org.apache.commons.math.MathConfigurationException ex = new org.apache.commons.math.MathConfigurationException(cause);26 junit.framework.Assert.assertEquals(cause, ex.getCause());27 }28 public void testConstructorPatternArgumentsCause() {29 java.lang.String pattern = "a {0}x{1} matrix cannot be a rotation matrix";30 java.lang.Object[] arguments = new java.lang.Object[]{ java.lang.Integer.valueOf(6) , java.lang.Integer.valueOf(4) };31 java.lang.String inMsg = "inner message";32 java.lang.Exception cause = new java.lang.Exception(inMsg);33 org.apache.commons.math.MathConfigurationException ex = new org.apache.commons.math.MathConfigurationException(cause , pattern , arguments);34 junit.framework.Assert.assertEquals(cause, ex.getCause());35 junit.framework.Assert.assertEquals(pattern, ex.getPattern());36 junit.framework.Assert.assertEquals(arguments.length, ex.getArguments().length);37 for (int i = 0 ; i < (arguments.length) ; ++i) {38 junit.framework.Assert.assertEquals(arguments[i], ex.getArguments()[i]);39 }40 junit.framework.Assert.assertFalse(pattern.equals(ex.getMessage()));41 junit.framework.Assert.assertFalse(ex.getMessage().equals(ex.getMessage(java.util.Locale.FRENCH)));42 }43}...

Full Screen

Full Screen

Source:ResultTest.java Github

copy

Full Screen

1package org.onosproject.store.consistent.impl;2import static junit.framework.TestCase.assertEquals;3import static junit.framework.TestCase.assertFalse;4import static junit.framework.TestCase.assertNull;5import static junit.framework.TestCase.assertTrue;6import org.junit.Test;7/**8 * Unit tests for Result.9 */10public class ResultTest {11 @Test12 public void testLocked() {13 Result<String> r = Result.locked();14 assertFalse(r.success());15 assertNull(r.value());16 assertEquals(Result.Status.LOCKED, r.status());17 }18 @Test19 public void testOk() {20 Result<String> r = Result.ok("foo");21 assertTrue(r.success());22 assertEquals("foo", r.value());23 assertEquals(Result.Status.OK, r.status());24 }25 @Test26 public void testEquality() {27 Result<String> r1 = Result.ok("foo");28 Result<String> r2 = Result.locked();29 Result<String> r3 = Result.ok("bar");30 Result<String> r4 = Result.ok("foo");31 assertTrue(r1.equals(r4));32 assertFalse(r1.equals(r2));33 assertFalse(r1.equals(r3));34 assertFalse(r2.equals(r3));35 }36}...

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1package com.github.sonarlinttest.junit;2import junit.framework.Assert;3import org.junit.Test;4public class AssertTest {5 public void testAssertFalse() {6 boolean condition = false;7 Assert.assertFalse(condition);8 }9 public void testAssertTrue() {10 boolean condition = true;11 Assert.assertTrue(condition);12 }13 public void testFail() {14 Assert.fail("Not yet implemented");15 }16 public void testAssertEquals() {17 Assert.assertEquals("text", "text");18 }19 public void testAssertSame() {20 Integer aNumber = Integer.valueOf(768);21 Assert.assertSame(aNumber, aNumber);22 }23 public void testAssertNotSame() {24 Integer aNumber = Integer.valueOf(768);25 Integer anotherNumber = Integer.valueOf(768);26 Assert.assertNotSame(aNumber, anotherNumber);27 }28 public void testAssertNull() {29 Object object = null;30 Assert.assertNull(object);31 }

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1import junit.framework.Assert;2public class TestAssertFalse {3 public static void main(String[] args) {4 Assert.assertFalse(false);5 }6}7junit.framework.Assert.assertFalse(String message, boolean condition)8import junit.framework.Assert;9public class TestAssertFalse {10 public static void main(String[] args) {11 Assert.assertFalse("test failed", false);12 }13}14junit.framework.Assert.assertFalse(String message, boolean condition)15import junit.framework.Assert;16public class TestAssertFalse {17 public static void main(String[] args) {18 Assert.assertFalse("test failed", false);19 }20}21junit.framework.Assert.assertNotSame(Object expected, Object actual)

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1import junit.framework.Assert;2import org.junit.Test;3public class TestClass {4 public void testAssertFalse() {5 Assert.assertFalse("failure - should be false", false);6 }7}

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1package com.example;2import junit.framework.Assert;3import org.junit.Test;4public class ExampleTest {5public void testAssertFalse() {6Assert.assertFalse("failure - should be false", false);7}8}9at org.junit.Assert.assertEquals(Assert.java:115)10at org.junit.Assert.assertEquals(Assert.java:144)11at com.example.ExampleTest.testAssertFalse(ExampleTest.java:9)12package com.example;13import junit.framework.Assert;14import org.junit.Test;15public class ExampleTest {16public void testAssertTrue() {17Assert.assertTrue("failure - should be true", true);18}19}20at org.junit.Assert.assertEquals(Assert.java:115)21at org.junit.Assert.assertEquals(Assert.java:144)22at com.example.ExampleTest.testAssertTrue(ExampleTest.java:9)23package com.example;24import junit.framework.Assert;25import org.junit.Test;26public class ExampleTest {27public void testAssertSame() {28String expected = "test";29String actual = "test";30Assert.assertSame("failure - strings are not same", expected, actual);31}32}33at org.junit.Assert.assertEquals(Assert.java:115)34at org.junit.Assert.assertEquals(Assert.java:144)

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.junit.Assert;3public class AssertFalseTest {4 public void testAssertFalse() {5 Assert.assertFalse(false);6 }7}8 at org.junit.Assert.assertEquals(Assert.java:115)9 at org.junit.Assert.assertFalse(Assert.java:64)10 at org.junit.Assert.assertFalse(Assert.java:74)11 at AssertFalseTest.testAssertFalse(AssertFalseTest.java:15)12assertTrue(boolean condition)13import org.junit.Test;14import org.junit.Assert;15public class AssertTrueTest {16 public void testAssertTrue() {17 Assert.assertTrue(true);18 }19}20assertEquals(Object expected, Object actual)21import org.junit.Test;22import org.junit.Assert;23public class AssertEqualsTest {24 public void testAssertEquals() {25 Assert.assertEquals("text", "text");26 }27}28assertSame(Object expected, Object actual)29import org.junit.Test;30import org.junit.Assert;31public class AssertSameTest {32 public void testAssertSame() {33 String str = new String ("text");34 Assert.assertSame(str,str);35 }36}37assertNotSame(Object unexpected, Object actual)38import org.junit.Test;39import org.junit.Assert;

Full Screen

Full Screen

assertFalse

Using AI Code Generation

copy

Full Screen

1public class JunitExample {2 public void test() {3 assertFalse("failure - should be false", false);4 }5}6JUnit Test Case Example using assertTrue() method7import org.junit.Test;8import static org.junit.Assert.*;9public class JunitExample {10 public void test() {11 assertTrue("failure - should be true", true);12 }13}14JUnit Test Case Example using assertNotNull() method15import org.junit.Test;16import static org.junit.Assert.*;17public class JunitExample {18 public void test() {19 assertNotNull("should not be null", new Object());20 }21}22JUnit Test Case Example using assertNull() method23import org.junit.Test;24import static org.junit.Assert.*;25public class JunitExample {26 public void test() {27 assertNull("should be null", null);28 }29}30JUnit Test Case Example using assertSame() method31import org.junit.Test;32import static org.junit.Assert.*;33public class JunitExample {34 public void test() {35 Integer aNumber = Integer.valueOf(768);36 assertSame("should be same", aNumber, aNumber);37 }38}39JUnit Test Case Example using assertNotSame() method40import org.junit.Test;41import static org.junit.Assert.*;42public class JunitExample {43 public void test() {44 assertNotSame("should not be same Object", new Object(), new Object());45 }46}47JUnit Test Case Example using assertArrayEquals() method48import org.junit.Test;49import static org.junit.Assert.*;50public class JunitExample {51 public void test() {52 byte[] expected = "trial".getBytes();53 byte[] actual = "trial".getBytes();54 assertArrayEquals("failure - byte arrays not same", expected, actual);55 }56}57JUnit Test Case Example using assertEquals() method58import org.junit.Test;59import static org.junit.Assert.*;60public class JunitExample {61 public void test() {62 assertEquals("failure - strings are not equal", "text", "text");63 }64}65JUnit Test Case Example using assertNotEquals() method66import org.junit.Test;67import static org

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful