Exemplo n.º 1
0
 @Test
 public void toLong() throws Exception {
   assertThat(RubyUtils.toLong(null)).isNull();
   assertThat(RubyUtils.toLong(2)).isEqualTo(2L);
   assertThat(RubyUtils.toLong(3L)).isEqualTo(3L);
   assertThat(RubyUtils.toLong("4")).isEqualTo(4L);
 }
Exemplo n.º 2
0
 @Test
 public void should_parse_list_of_strings() {
   assertThat(RubyUtils.toStrings(null)).isNull();
   assertThat(RubyUtils.toStrings("")).isEmpty();
   assertThat(RubyUtils.toStrings("foo")).containsOnly("foo");
   assertThat(RubyUtils.toStrings("foo,bar")).containsOnly("foo", "bar");
   assertThat(RubyUtils.toStrings(asList("foo", "bar"))).containsOnly("foo", "bar");
 }
Exemplo n.º 3
0
 @Test
 public void toDouble() throws Exception {
   assertThat(RubyUtils.toDouble(null)).isNull();
   assertThat(RubyUtils.toDouble("")).isNull();
   assertThat(RubyUtils.toDouble("  ")).isNull();
   assertThat(RubyUtils.toDouble("123")).isEqualTo(123.0);
   assertThat(RubyUtils.toDouble("3.14")).isEqualTo(3.14);
   assertThat(RubyUtils.toDouble(3.14)).isEqualTo(3.14);
   assertThat(RubyUtils.toDouble(123)).isEqualTo(123.0);
   assertThat(RubyUtils.toDouble(123L)).isEqualTo(123.0);
 }
Exemplo n.º 4
0
 @Test
 public void toDate() throws Exception {
   assertThat(RubyUtils.toDate(null)).isNull();
   assertThat(RubyUtils.toDate("")).isNull();
   assertThat(RubyUtils.toDate("   ")).isNull();
   assertThat(RubyUtils.toDate("2013-01-18").getDate()).isEqualTo(18);
   assertThat(RubyUtils.toDate("2013-01-18T15:38:19+0200").getDate()).isEqualTo(18);
   assertThat(RubyUtils.toDate("2013-01-18T15:38:19+0200").getMinutes()).isEqualTo(38);
   assertThat(RubyUtils.toDate(DateUtils.parseDate("2013-01-18")).getDate()).isEqualTo(18);
 }
Exemplo n.º 5
0
 @Test
 public void toBoolean() throws Exception {
   assertThat(RubyUtils.toBoolean(null)).isNull();
   assertThat(RubyUtils.toBoolean("")).isNull();
   assertThat(RubyUtils.toBoolean("  ")).isNull();
   assertThat(RubyUtils.toBoolean("true")).isTrue();
   assertThat(RubyUtils.toBoolean(true)).isTrue();
   assertThat(RubyUtils.toBoolean("false")).isFalse();
   assertThat(RubyUtils.toBoolean(false)).isFalse();
 }
Exemplo n.º 6
0
 @Test
 public void toInteger() throws Exception {
   assertThat(RubyUtils.toInteger(null)).isNull();
   assertThat(RubyUtils.toInteger("")).isNull();
   assertThat(RubyUtils.toInteger("   ")).isNull();
   assertThat(RubyUtils.toInteger("123")).isEqualTo(123);
   assertThat(RubyUtils.toInteger(123)).isEqualTo(123);
   assertThat(RubyUtils.toInteger(123L)).isEqualTo(123);
 }
Exemplo n.º 7
0
 @Test
 public void toEnums() {
   assertThat(RubyUtils.toEnums(null, RuleStatus.class)).isNull();
   assertThat(RubyUtils.toEnums("", RuleStatus.class)).isEmpty();
   assertThat(RubyUtils.toEnums("BETA", RuleStatus.class)).containsOnly(RuleStatus.BETA);
   assertThat(RubyUtils.toEnums("BETA,READY", RuleStatus.class))
       .containsOnly(RuleStatus.BETA, RuleStatus.READY);
   assertThat(RubyUtils.toEnums(asList("BETA", "READY"), RuleStatus.class))
       .containsOnly(RuleStatus.BETA, RuleStatus.READY);
   try {
     RubyUtils.toEnums("xxx", RuleStatus.class);
     fail();
   } catch (IllegalArgumentException e) {
     // success
   }
   try {
     RubyUtils.toEnums(1, RuleStatus.class);
     fail();
   } catch (IllegalArgumentException e) {
     assertThat(e).hasMessage("Unsupported type: class java.lang.Integer");
   }
 }
Exemplo n.º 8
0
  @Test
  public void toBoolean_unexpected_class() throws Exception {
    throwable.expect(IllegalArgumentException.class);

    RubyUtils.toBoolean(333);
  }
Exemplo n.º 9
0
  @Test
  public void toDouble_unexpected_class() throws Exception {
    throwable.expect(IllegalArgumentException.class);

    RubyUtils.toDouble(true);
  }
Exemplo n.º 10
0
  @Test
  public void toInteger_unexpected_class() throws Exception {
    throwable.expect(IllegalArgumentException.class);

    RubyUtils.toInteger(1.2);
  }
Exemplo n.º 11
0
  @Test
  public void toLong_unexpected_class() throws Exception {
    throwable.expect(IllegalArgumentException.class);

    RubyUtils.toLong(false);
  }
Exemplo n.º 12
0
  @Test
  public void toDate_bad_format() throws Exception {
    throwable.expect(SonarException.class);

    RubyUtils.toDate("01/02/2013");
  }
Exemplo n.º 13
0
  @Test
  public void toDate_unexpected_class() {
    throwable.expect(IllegalArgumentException.class);

    RubyUtils.toDate(333);
  }