コード例 #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);
 }