예제 #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);
 }