Esempio n. 1
0
 /** Test of compareTo method, of class Time. */
 @Test
 public void testCompareTo() {
   System.out.println("compareTo");
   assertEquals("time == time | Time is hetzelfde", 0, time.compareTo(time));
   assertEquals("time != time | Time is niet hetzelfde", 1, time.compareTo(time.plus(5)));
   assertEquals("time == time | Time is hetzelfde", 0, time.plus(5).compareTo(time.plus(5)));
 }
Esempio n. 2
0
  @Test
  public void timestamp() throws SQLException {
    connectWithJulianDayModeActivated();
    long now = System.currentTimeMillis();
    Timestamp d1 = new Timestamp(now);
    Date d2 = new Date(now);
    Time d3 = new Time(now);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTimestamp(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1, rs.getTimestamp(1));

    rs = stat.executeQuery("select date(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d2.toString(), rs.getString(1));

    rs = stat.executeQuery("select time(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d3.toString(), rs.getString(1));

    rs = stat.executeQuery("select strftime('%Y-%m-%d %H:%M:%f', c1, 'localtime') from t;");
    assertTrue(rs.next());
    // assertEquals(d1.toString(), rs.getString(1)); // ms are not occurate...
  }
Esempio n. 3
0
  /** Test of difference method, of class Time. */
  @Test
  public void testDifference() {
    System.out.println("difference");
    Time instance = (Time) time.plus(1000);
    int expResult = -1000;
    int result = time.difference(instance);
    assertEquals("Resultaat moet in de min zijn", expResult, result);

    instance = (Time) time.plus(-1000);
    expResult = 1000;
    result = time.difference(instance);
    assertEquals("Resultaat moet in de plus zijn", expResult, result);
  }
Esempio n. 4
0
  @Test
  public void testTimeConverter() {
    String sql = "select current_time as col1 from (values(0))";

    Time sqlTime = sql2o.createQuery(sql).executeScalar(Time.class);
    assertThat(sqlTime, is(notNullValue()));
    assertTrue(sqlTime.getTime() > 0);

    Date date = sql2o.createQuery(sql).executeScalar(Date.class);
    assertThat(date, is(notNullValue()));

    LocalTime jodaTime = sql2o.createQuery(sql).executeScalar(LocalTime.class);
    assertTrue(jodaTime.getMillisOfDay() > 0);
    assertThat(jodaTime.getHourOfDay(), is(equalTo(new LocalTime().getHourOfDay())));
  }
Esempio n. 5
0
  @SuppressWarnings("deprecation")
  @Test
  public void time() throws SQLException {
    connectWithJulianDayModeActivated();
    Time d1 = new Time(System.currentTimeMillis());

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTime(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getHours(), rs.getTime(1).getHours());
    assertEquals(d1.getMinutes(), rs.getTime(1).getMinutes());
    assertEquals(d1.getSeconds(), rs.getTime(1).getSeconds());
  }
Esempio n. 6
0
  /** Test of plus method, of class Time. */
  @Test
  public void testPlus() {
    System.out.println("plus");
    int minutes = 22;
    Time expResult = new Time(1992, 10, 31, 12, 4);
    ITime result = this.time.plus(minutes);

    assertEquals("Uur moet nu 12 zijn", expResult.getHours(), result.getHours());
    assertEquals("Minuten moeten nu 4 zijn", expResult.getMinutes(), result.getMinutes());
    assertEquals("Dag mag niet verandert zijn", expResult.getDay(), result.getDay());
    assertEquals("Maand mag niet verandert zijn", expResult.getMonth(), result.getMonth());
    assertEquals("Jaar mag niet verandert zijn", expResult.getYear(), result.getYear());
  }