示例#1
0
 @Test
 public void formatTest1() {
   Formatter format = new Formatter();
   String result = formatter.format("{0:.2f}", 3.1415926);
   Assert.assertEquals(format.format("%.2f", 3.1415926).toString(), result);
   format.close();
 }
示例#2
0
  @Test
  public void otherExtractorError() {
    class TestClass {
      public Object a = null;
    }

    String result = formatter.format("Test {0.a.b}", new TestClass());
    Assert.assertEquals("Test ", result);
  }
示例#3
0
  @Test
  public void extractorFieldNotFound() {
    class TestClass {
      public int a = 10;
    }

    String result = formatter.format("Test {0.a}, {0.b}", new TestClass());
    Assert.assertEquals("Test 10, ", result);
  }
示例#4
0
  @Test
  public void extractorTest1() {
    class TestClass {
      public int a = 10;
    }

    class TestClassSon extends TestClass {
      public int b = 20;
    }

    String result = formatter.format("Test {0.a}, {0.b}", new TestClassSon());
    assertEquals(result, "Test 10, 20");
  }
示例#5
0
  @Test
  public void moreComplexExctractor() {
    class TestClassA {
      public int a = 10;
    }

    class TestClassB {
      TestClassA b = new TestClassA();
    }

    String result = formatter.format("Test {0.b.a}", new TestClassB());
    Assert.assertEquals("Test 10", result);
  }
示例#6
0
 @Test
 public void formatterIncorrectIndex3() {
   thrown.expectMessage("Index 5 is out of range");
   formatter.format("test{5}", 1);
 }
示例#7
0
 @Test
 public void formatterIncorrectIndex2() {
   thrown.expectMessage("Incorrect number: blah");
   formatter.format("test{blah.blah}", 1);
 }
示例#8
0
 @Test
 public void formatterNullArgs() {
   String result = formatter.format("test{0}test", null);
   Assert.assertEquals("testtest", result);
 }
示例#9
0
 @Test
 public void formatterNothingToDoHere() {
   String result = formatter.format("Test", 1, 2, 3);
   Assert.assertEquals(result, "Test");
 }
示例#10
0
 @Test
 public void simpleFormat() {
   String result = formatter.format("Test {{ {0}, {1}, }} {{, {2} }}{{}}", 1, 2, 3);
   Assert.assertEquals(result, "Test { 1, 2, } {, 3 }{}");
 }
示例#11
0
 @Test
 public void formatterFormatingOfNull() {
   thrown.expectMessage("Null can't be formatted");
   formatter.format("{0:f}", (Object) null);
 }
示例#12
0
 @Test
 public void noFormatter() {
   Calendar c = Calendar.getInstance();
   thrown.expectMessage("There is no good formatter for class " + c.getClass().getName());
   String result = formatter.format("{0:04d}", c);
 }
示例#13
0
 @Test
 public void formatTest2() {
   String result = formatter.format("{0:04d}", new BigInteger("31"));
   Assert.assertEquals("0031", result);
 }
示例#14
0
 @Test
 public void formatterIncorrectIndex6() {
   thrown.expectMessage("Index 2 is out of range");
   formatter.format("test{2.blah}", 1);
 }
示例#15
0
 @Test
 public void formatterAndNull() {
   String result = formatter.format("test{0}test{1}test{2}", null, null, null);
   assertEquals("testtesttest", result);
 }
示例#16
0
 @Test
 public void formatterIncorrectIndex7() {
   thrown.expectMessage("Incorrect number: +0");
   formatter.format("{+0}", "1");
 }
示例#17
0
 @Test
 public void incorrectPattern() {
   thrown.expectMessage("Incorrect pattern: \".2f\"");
   String result = formatter.format("{0:.2f}", new BigInteger("31"));
 }
示例#18
0
 @Test
 public void formatterEmptyFieldName() {
   thrown.expectMessage("Field of class can't have empty name");
   formatter.format("{0.}", 1);
 }
示例#19
0
 @Test
 public void emptyPattern() {
   thrown.expectMessage("Pattern must be non empty string");
   String result = formatter.format("{0:}", new BigInteger("31"));
 }
示例#20
0
 @Test
 public void formatterNullFormat() {
   thrown.expectMessage("Format musn't be null");
   formatter.format(null, 1, 2, 3);
 }
示例#21
0
 @Test
 public void formatterNullBuffer() {
   thrown.expectMessage("Buffer musn't be null");
   formatter.format((StringBuilder) null, "Test {0}", 1);
 }
示例#22
0
 @Test
 public void formatterBracketTest1() {
   thrown.expectMessage("Unexpected opened bracket");
   String result = formatter.format("blah { Test", 1, 2, 3);
 }
示例#23
0
 @Test
 public void formatterBracketTest4() {
   thrown.expectMessage("Unexpected closed bracket");
   String result = formatter.format("blah Test}", 1, 2, 3);
 }