hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/test/hivemind/test/util TestBodyBuilder.java
Date Wed, 14 Apr 2004 21:08:43 GMT
hlship      2004/04/14 14:08:43

  Modified:    framework/src/java/org/apache/hivemind/service
                        BodyBuilder.java
               framework/src/test/hivemind/test/util TestBodyBuilder.java
  Log:
  Add additional methods to BodyBuilder to make it easier to add text using MessageFormat
patterns and arguments.
  
  Revision  Changes    Path
  1.2       +82 -1     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/BodyBuilder.java
  
  Index: BodyBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/BodyBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BodyBuilder.java	26 Feb 2004 23:07:49 -0000	1.1
  +++ BodyBuilder.java	14 Apr 2004 21:08:43 -0000	1.2
  @@ -14,6 +14,8 @@
   
   package org.apache.hivemind.service;
   
  +import java.text.MessageFormat;
  +
   /**
    * Utility class for assembling the <em>body</em> used with
    * Javassist as a method or catch block.
  @@ -59,6 +61,84 @@
       }
   
       /**
  +     * Adds text to the current line, without terminating the line.
  +     * 
  +     * @param pattern a string pattern, used with {@link java.text.MessageFormat#format(java.lang.String,
java.lang.Object[])}
  +     * @param arguments arguments used witht the format string
  +     */
  +
  +    public void add(String pattern, Object[] arguments)
  +    {
  +        add(MessageFormat.format(pattern, arguments));
  +    }
  +
  +    /**
  +     * Convience for {@link #add(String, Object[])
  +     */
  +
  +    public void add(String pattern, Object arg0)
  +    {
  +        add(pattern, new Object[] { arg0 });
  +    }
  +
  +    /**
  +     * Convience for {@link #add(String, Object[])
  +     */
  +
  +    public void add(String pattern, Object arg0, Object arg1)
  +    {
  +        add(pattern, new Object[] { arg0, arg1 });
  +    }
  +
  +    /**
  +     * Convience for {@link #add(String, Object[])
  +     */
  +
  +    public void add(String pattern, Object arg0, Object arg1, Object arg2)
  +    {
  +        add(pattern, new Object[] { arg0, arg1, arg2 });
  +    }
  +
  +    /**
  +     * Adds text to the current line then terminates the line.
  +     * 
  +     * @param pattern a string pattern, used with {@link java.text.MessageFormat#format(java.lang.String,
java.lang.Object[])}
  +     * @param arguments arguments used witht the format string
  +     */
  +
  +    public void addln(String pattern, Object[] arguments)
  +    {
  +        addln(MessageFormat.format(pattern, arguments));
  +    }
  +
  +    /**
  +     * Convience for {@link #addln(String, Object[])
  +     */
  +
  +    public void addln(String pattern, Object arg0)
  +    {
  +        addln(pattern, new Object[] { arg0 });
  +    }
  +
  +    /**
  +     * Convience for {@link #addln(String, Object[])
  +     */
  +
  +    public void addln(String pattern, Object arg0, Object arg1)
  +    {
  +        addln(pattern, new Object[] { arg0, arg1 });
  +    }
  +
  +    /**
  +     * Convience for {@link #addln(String, Object[])
  +     */
  +
  +    public void addln(String pattern, Object arg0, Object arg1, Object arg2)
  +    {
  +        addln(pattern, new Object[] { arg0, arg1, arg2 });
  +    }
  +
  +    /**
        * Adds the text to the current line, surrounded by double quotes.
        * <em>Does not escape quotes in the text</em>.
        */
  @@ -115,6 +195,7 @@
   
           indent();
           _buffer.append("}");
  +        
           newline();
       }
   
  
  
  
  1.5       +43 -1     jakarta-hivemind/framework/src/test/hivemind/test/util/TestBodyBuilder.java
  
  Index: TestBodyBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/util/TestBodyBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBodyBuilder.java	26 Feb 2004 23:08:04 -0000	1.4
  +++ TestBodyBuilder.java	14 Apr 2004 21:08:43 -0000	1.5
  @@ -84,4 +84,46 @@
           assertEquals("barney", _b.toString());
       }
   
  +    public void testAddPattern1()
  +    {
  +        _b.add("today is {0}.", "tuesday");
  +
  +        assertEquals("today is tuesday.", _b.toString());
  +    }
  +
  +    public void testAddlnPattern1()
  +    {
  +        _b.addln("The capital of France is {0}.", "Paris");
  +
  +        assertEquals("The capital of France is Paris.\n", _b.toString());
  +    }
  +
  +    public void testAddPattern2()
  +    {
  +        _b.add("Current suspects are: {0} and {1}.", "Tony", "Junior");
  +
  +        assertEquals("Current suspects are: Tony and Junior.", _b.toString());
  +    }
  +
  +    public void testAddlnPattern2()
  +    {
  +        _b.addln("The capital of {0} is {1}.", "Germany", "Berlin");
  +
  +        assertEquals("The capital of Germany is Berlin.\n", _b.toString());
  +    }
  +
  +    public void testAddPattern3()
  +    {
  +        _b.add("{0} + {1} = {2}", new Integer(5), new Integer(7), new Integer(13));
  +
  +        assertEquals("5 + 7 = 13", _b.toString());
  +    }
  +
  +    public void testAddlnPattern3()
  +    {
  +        _b.addln("The Holy Trinity: {0}, {1} and {2}.", "Tapestry", "HiveMind", "Hibernate");
  +
  +        assertEquals("The Holy Trinity: Tapestry, HiveMind and Hibernate.\n", _b.toString());
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message