@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();
 }
  @Test
  public void otherExtractorError() {
    class TestClass {
      public Object a = null;
    }

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