コード例 #1
0
  @Test
  public void customFormatsAutoLoading() {

    MessageFormat extformat =
        new MessageFormat(
            "hello {0, number}{1, mask, __ ____}xxx {2, date, ddmmyy} abc {3, mask, ___ ___}");
    String out = extformat.render(100000, 313378, new Date(0), 313378);

    Assert.assertEquals(out, "hello 100,00031 3378xxx  010070 abc 313 378");

    Assert.assertEquals(Humanize.format("{0, mask, __ __}", 1100), "11 00");
  }
コード例 #2
0
  @Test
  public void customFormats() {

    HashMap<String, FormatFactory> registry = new HashMap<String, FormatFactory>();
    registry.put("mask", MaskFormat.factory());

    MessageFormat extformat =
        new MessageFormat(
            "hello {0, number}{1, mask, __ ____}xxx {2, date, ddmmyy} abc {3, mask, ___ ___}",
            registry);
    String out = extformat.render(100000, 313378, new Date(0), 313378);

    Assert.assertEquals(out, "hello 100,00031 3378xxx  010070 abc 313 378");
  }
コード例 #3
0
  @Test(expectedExceptions = IllegalArgumentException.class)
  public void unknownFormat() {

    MessageFormat extformat = new MessageFormat("ok {0, unknown} test");
    extformat.render(1);
  }
コード例 #4
0
  @Test
  public void humanizeFormats() {

    MessageFormat extformat = new MessageFormat("{0, humanize, binaryPrefix}");
    Assert.assertEquals(extformat.render(10000), "9.8 KB");
  }
コード例 #5
0
  @Test
  public void bypass() {

    MessageFormat extformat = new MessageFormat("ok-ay");
    Assert.assertEquals(extformat.render(), "ok-ay");
  }