View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.log4j;
18  
19  import junit.framework.TestCase;
20  
21  import java.io.CharArrayWriter;
22  import java.text.MessageFormat;
23  import java.util.Date;
24  
25  
26  /***
27   * Unit test for LogSF.
28   */
29  public class TestLogSF extends TestCase {
30      /***
31       * Trace level.
32       */
33      private static final Level TRACE = getTraceLevel();
34  
35      /***
36       * Gets Trace level.
37       * Trace level was not defined prior to log4j 1.2.12.
38       * @return trace level
39       */
40      private static Level getTraceLevel() {
41          try {
42              return (Level) Level.class.getField("TRACE").get(null);
43          } catch(Exception ex) {
44              return new Level(5000, "TRACE", 7);
45          }
46      }
47  
48      /***
49       * Logger.
50       */
51      private final Logger logger = Logger.getLogger(
52              "org.apache.log4j.formatter.TestLogSF");
53  
54      /***
55       * Create the test case
56       *
57       * @param testName name of the test case
58       */
59      public TestLogSF(String testName) {
60          super(testName);
61      }
62  
63  
64      /***
65       * Post test clean up.
66       */
67      public void tearDown() {
68          LogManager.resetConfiguration();
69      }
70  
71      /***
72       * Test class name when logging through LogSF.
73       */
74      public void testClassName() {
75          CharArrayWriter writer = new CharArrayWriter();
76          PatternLayout layout = new PatternLayout("%C");
77          WriterAppender appender = new WriterAppender(layout, writer);
78          appender.activateOptions();
79          Logger.getRootLogger().addAppender(appender);
80          LogSF.debug(logger, null, Math.PI);
81          assertEquals(TestLogSF.class.getName(), writer.toString());
82      }
83  
84  
85  
86      /***
87       * Test LogSF.trace with null pattern.
88       */
89      public void testTraceNullPattern() {
90          LogCapture capture = new LogCapture(TRACE);
91          logger.setLevel(TRACE);
92          LogSF.trace(logger, null, Math.PI);
93          assertNull(capture.getMessage());
94      }
95  
96      /***
97       * Test LogSF.trace with no-field pattern.
98       */
99      public void testTraceNoArg() {
100         LogCapture capture = new LogCapture(TRACE);
101         logger.setLevel(TRACE);
102         LogSF.trace(logger, "Hello, World", Math.PI);
103         assertEquals("Hello, World", capture.getMessage());
104     }
105 
106     /***
107      * Test LogSF.trace with malformed pattern.
108      */
109     public void testTraceBadPattern() {
110         LogCapture capture = new LogCapture(TRACE);
111         logger.setLevel(TRACE);
112         LogSF.trace(logger, "Hello, {.", Math.PI);
113         assertEquals("Hello, {.", capture.getMessage());
114     }
115 
116     /***
117      * Test LogSF.trace with missing argument.
118      */
119     public void testTraceMissingArg() {
120         LogCapture capture = new LogCapture(TRACE);
121         logger.setLevel(TRACE);
122         LogSF.trace(logger, "Hello, {}World", new Object[0]);
123         assertEquals("Hello, {}World", capture.getMessage());
124     }
125 
126     /***
127      * Test LogSF.trace with single field pattern with string argument.
128      */
129     public void testTraceString() {
130         LogCapture capture = new LogCapture(TRACE);
131         logger.setLevel(TRACE);
132         LogSF.trace(logger, "Hello, {}", "World");
133         assertEquals("Hello, World", capture.getMessage());
134     }
135 
136     /***
137      * Test LogSF.trace with single field pattern with null argument.
138      */
139     public void testTraceNull() {
140         LogCapture capture = new LogCapture(TRACE);
141         logger.setLevel(TRACE);
142         LogSF.trace(logger, "Hello, {}", (Object) null);
143         assertEquals("Hello, null", capture.getMessage());
144     }
145 
146     /***
147      * Test LogSF.trace with single field pattern with int argument.
148      */
149     public void testTraceInt() {
150         LogCapture capture = new LogCapture(TRACE);
151         logger.setLevel(TRACE);
152         int val = 42;
153         LogSF.trace(logger, "Iteration {}", val);
154         assertEquals("Iteration 42", capture.getMessage());
155     }
156 
157     /***
158      * Test LogSF.trace with single field pattern with byte argument.
159      */
160     public void testTraceByte() {
161         LogCapture capture = new LogCapture(TRACE);
162         logger.setLevel(TRACE);
163         byte val = 42;
164         LogSF.trace(logger, "Iteration {}", val);
165         assertEquals("Iteration 42", capture.getMessage());
166     }
167 
168     /***
169      * Test LogSF.trace with single field pattern with short argument.
170      */
171     public void testTraceShort() {
172         LogCapture capture = new LogCapture(TRACE);
173         logger.setLevel(TRACE);
174         short val = 42;
175         LogSF.trace(logger, "Iteration {}", val);
176         assertEquals("Iteration 42", capture.getMessage());
177     }
178 
179     /***
180      * Test LogSF.trace with single field pattern with long argument.
181      */
182     public void testTraceLong() {
183         LogCapture capture = new LogCapture(TRACE);
184         logger.setLevel(TRACE);
185         long val = 42;
186         LogSF.trace(logger, "Iteration {}", val);
187         assertEquals("Iteration 42", capture.getMessage());
188     }
189 
190     /***
191      * Test LogSF.trace with single field pattern with char argument.
192      */
193     public void testTraceChar() {
194         LogCapture capture = new LogCapture(TRACE);
195         logger.setLevel(TRACE);
196         char val = 'C';
197         LogSF.trace(logger, "Iteration {}", val);
198         assertEquals("Iteration C", capture.getMessage());
199     }
200 
201     /***
202      * Test LogSF.trace with single field pattern with boolean argument.
203      */
204     public void testTraceBoolean() {
205         LogCapture capture = new LogCapture(TRACE);
206         logger.setLevel(TRACE);
207         boolean val = true;
208         LogSF.trace(logger, "Iteration {}", val);
209         assertEquals("Iteration true", capture.getMessage());
210     }
211 
212     /***
213      * Test LogSF.trace with single field pattern with float argument.
214      */
215     public void testTraceFloat() {
216         LogCapture capture = new LogCapture(TRACE);
217         logger.setLevel(TRACE);
218         float val = 3.14f;
219         LogSF.trace(logger, "Iteration {}", val);
220         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
221     }
222 
223     /***
224      * Test LogSF.trace with single field pattern with double argument.
225      */
226     public void testTraceDouble() {
227         LogCapture capture = new LogCapture(TRACE);
228         logger.setLevel(TRACE);
229         double val = 3.14;
230         LogSF.trace(logger, "Iteration {}", val);
231         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
232     }
233 
234     /***
235      * Test LogSF.trace with two arguments.
236      */
237     public void testTraceTwoArg() {
238         LogCapture capture = new LogCapture(TRACE);
239         logger.setLevel(TRACE);
240         LogSF.trace(logger, "{}, {}.", "Hello", "World");
241         assertEquals("Hello, World.", capture.getMessage());
242 
243     }
244 
245     /***
246      * Test LogSF.trace with three arguments.
247      */
248     public void testTraceThreeArg() {
249         LogCapture capture = new LogCapture(TRACE);
250         logger.setLevel(TRACE);
251         LogSF.trace(logger, "{}{} {}.", "Hello", ",", "World");
252         assertEquals("Hello, World.", capture.getMessage());
253     }
254 
255     /***
256      * Test LogSF.trace with Object[] argument.
257      */
258     public void testTraceFourArg() {
259         LogCapture capture = new LogCapture(TRACE);
260         logger.setLevel(TRACE);
261         LogSF.trace(logger, "{}{} {}{}", "Hello", ",", "World", ".");
262         assertEquals("Hello, World.", capture.getMessage());
263     }
264 
265     /***
266      * Test LogSF.trace with Object[] argument.
267      */
268     public void testTraceArrayArg() {
269         LogCapture capture = new LogCapture(TRACE);
270         logger.setLevel(TRACE);
271         Object[] args = new Object[] { "Hello", ",", "World", "." };
272         LogSF.trace(logger, "{}{} {}{}", args);
273         assertEquals("Hello, World.", capture.getMessage());
274     }
275 
276     /***
277      * Test LogSF.trace with null Object[] argument.
278      */
279     public void testTraceNullArrayArg() {
280         LogCapture capture = new LogCapture(TRACE);
281         logger.setLevel(TRACE);
282         Object[] args = null;
283         LogSF.trace(logger, "{}{} {}{}", args);
284         assertEquals("{}{} {}{}", capture.getMessage());
285     }
286 
287 
288 
289     /***
290      * Test LogSF.debug with null pattern.
291      */
292     public void testDebugNullPattern() {
293         LogCapture capture = new LogCapture(Level.DEBUG);
294         LogSF.debug(logger, null, Math.PI);
295         assertNull(capture.getMessage());
296     }
297 
298     /***
299      * Test LogSF.debug with no-field pattern.
300      */
301     public void testDebugNoArg() {
302         LogCapture capture = new LogCapture(Level.DEBUG);
303         LogSF.debug(logger, "Hello, World", Math.PI);
304         assertEquals("Hello, World", capture.getMessage());
305     }
306 
307     /***
308      * Test LogSF.debug with malformed pattern.
309      */
310     public void testDebugBadPattern() {
311         LogCapture capture = new LogCapture(Level.DEBUG);
312         LogSF.debug(logger, "Hello, {.", Math.PI);
313         assertEquals("Hello, {.", capture.getMessage());
314     }
315 
316     /***
317      * Test LogSF.debug with missing argument.
318      */
319     public void testDebugMissingArg() {
320         LogCapture capture = new LogCapture(Level.DEBUG);
321         LogSF.debug(logger, "Hello, {}World", new Object[0]);
322         assertEquals("Hello, {}World", capture.getMessage());
323     }
324 
325     /***
326      * Test LogSF.debug with single field pattern with string argument.
327      */
328     public void testDebugString() {
329         LogCapture capture = new LogCapture(Level.DEBUG);
330         LogSF.debug(logger, "Hello, {}", "World");
331         assertEquals("Hello, World", capture.getMessage());
332     }
333 
334     /***
335      * Test LogSF.debug with single field pattern with null argument.
336      */
337     public void testDebugNull() {
338         LogCapture capture = new LogCapture(Level.DEBUG);
339         LogSF.debug(logger, "Hello, {}", (Object) null);
340         assertEquals("Hello, null", capture.getMessage());
341     }
342 
343     /***
344      * Test LogSF.debug with single field pattern with int argument.
345      */
346     public void testDebugInt() {
347         LogCapture capture = new LogCapture(Level.DEBUG);
348         int val = 42;
349         LogSF.debug(logger, "Iteration {}", val);
350         assertEquals("Iteration 42", capture.getMessage());
351     }
352 
353     /***
354      * Test LogSF.debug with single field pattern with byte argument.
355      */
356     public void testDebugByte() {
357         LogCapture capture = new LogCapture(Level.DEBUG);
358         byte val = 42;
359         LogSF.debug(logger, "Iteration {}", val);
360         assertEquals("Iteration 42", capture.getMessage());
361     }
362 
363     /***
364      * Test LogSF.debug with single field pattern with short argument.
365      */
366     public void testDebugShort() {
367         LogCapture capture = new LogCapture(Level.DEBUG);
368         short val = 42;
369         LogSF.debug(logger, "Iteration {}", val);
370         assertEquals("Iteration 42", capture.getMessage());
371     }
372 
373     /***
374      * Test LogSF.debug with single field pattern with long argument.
375      */
376     public void testDebugLong() {
377         LogCapture capture = new LogCapture(Level.DEBUG);
378         long val = 42;
379         LogSF.debug(logger, "Iteration {}", val);
380         assertEquals("Iteration 42", capture.getMessage());
381     }
382 
383     /***
384      * Test LogSF.debug with single field pattern with char argument.
385      */
386     public void testDebugChar() {
387         LogCapture capture = new LogCapture(Level.DEBUG);
388         char val = 'C';
389         LogSF.debug(logger, "Iteration {}", val);
390         assertEquals("Iteration C", capture.getMessage());
391     }
392 
393     /***
394      * Test LogSF.debug with single field pattern with boolean argument.
395      */
396     public void testDebugBoolean() {
397         LogCapture capture = new LogCapture(Level.DEBUG);
398         boolean val = true;
399         LogSF.debug(logger, "Iteration {}", val);
400         assertEquals("Iteration true", capture.getMessage());
401     }
402 
403     /***
404      * Test LogSF.debug with single field pattern with float argument.
405      */
406     public void testDebugFloat() {
407         LogCapture capture = new LogCapture(Level.DEBUG);
408         float val = 3.14f;
409         LogSF.debug(logger, "Iteration {}", val);
410         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
411     }
412 
413     /***
414      * Test LogSF.debug with single field pattern with double argument.
415      */
416     public void testDebugDouble() {
417         LogCapture capture = new LogCapture(Level.DEBUG);
418         double val = 3.14;
419         LogSF.debug(logger, "Iteration {}", val);
420         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
421     }
422 
423     /***
424      * Test LogSF.debug with two arguments.
425      */
426     public void testDebugTwoArg() {
427         LogCapture capture = new LogCapture(Level.DEBUG);
428         LogSF.debug(logger, "{}, {}.", "Hello", "World");
429         assertEquals("Hello, World.", capture.getMessage());
430 
431     }
432 
433     /***
434      * Test LogSF.debug with three arguments.
435      */
436     public void testDebugThreeArg() {
437         LogCapture capture = new LogCapture(Level.DEBUG);
438         LogSF.debug(logger, "{}{} {}.", "Hello", ",", "World");
439         assertEquals("Hello, World.", capture.getMessage());
440     }
441 
442     /***
443      * Test LogSF.debug with four arguments.
444      */
445     public void testDebugFourArg() {
446         LogCapture capture = new LogCapture(Level.DEBUG);
447         LogSF.debug(logger, "{}{} {}{}", "Hello", ",", "World", ".");
448         assertEquals("Hello, World.", capture.getMessage());
449     }
450 
451     /***
452      * Test LogSF.debug with Object[] argument.
453      */
454     public void testDebugArrayArg() {
455         LogCapture capture = new LogCapture(Level.DEBUG);
456         Object[] args = new Object[] { "Hello", ",", "World", "." };
457         LogSF.debug(logger, "{}{} {}{}", args);
458         assertEquals("Hello, World.", capture.getMessage());
459     }
460 
461     /***
462      * Test LogSF.debug with null Object[] argument.
463      */
464     public void testDebugNullArrayArg() {
465         LogCapture capture = new LogCapture(Level.DEBUG);
466         Object[] args = null;
467         LogSF.debug(logger, "{}{} {}{}", args);
468         assertEquals("{}{} {}{}", capture.getMessage());
469     }
470 
471     /***
472      * Test LogSF.info with null pattern.
473      */
474     public void testInfoNullPattern() {
475         LogCapture capture = new LogCapture(Level.INFO);
476         LogSF.info(logger, null, Math.PI);
477         assertNull(capture.getMessage());
478     }
479 
480     /***
481      * Test LogSF.info with no-field pattern.
482      */
483     public void testInfoNoArg() {
484         LogCapture capture = new LogCapture(Level.INFO);
485         LogSF.info(logger, "Hello, World", Math.PI);
486         assertEquals("Hello, World", capture.getMessage());
487     }
488 
489     /***
490      * Test LogSF.info with malformed pattern.
491      */
492     public void testInfoBadPattern() {
493         LogCapture capture = new LogCapture(Level.INFO);
494         LogSF.info(logger, "Hello, {.", Math.PI);
495         assertEquals("Hello, {.", capture.getMessage());
496     }
497 
498     /***
499      * Test LogSF.info with missing argument.
500      */
501     public void testInfoMissingArg() {
502         LogCapture capture = new LogCapture(Level.INFO);
503         LogSF.info(logger, "Hello, {}World", new Object[0]);
504         assertEquals("Hello, {}World", capture.getMessage());
505     }
506 
507     /***
508      * Test LogSF.info with single field pattern with string argument.
509      */
510     public void testInfoString() {
511         LogCapture capture = new LogCapture(Level.INFO);
512         LogSF.info(logger, "Hello, {}", "World");
513         assertEquals("Hello, World", capture.getMessage());
514     }
515 
516     /***
517      * Test LogSF.info with single field pattern with null argument.
518      */
519     public void testInfoNull() {
520         LogCapture capture = new LogCapture(Level.INFO);
521         LogSF.info(logger, "Hello, {}", (Object) null);
522         assertEquals("Hello, null", capture.getMessage());
523     }
524 
525     /***
526      * Test LogSF.info with single field pattern with int argument.
527      */
528     public void testInfoInt() {
529         LogCapture capture = new LogCapture(Level.INFO);
530         int val = 42;
531         LogSF.info(logger, "Iteration {}", val);
532         assertEquals("Iteration 42", capture.getMessage());
533     }
534 
535     /***
536      * Test LogSF.info with single field pattern with byte argument.
537      */
538     public void testInfoByte() {
539         LogCapture capture = new LogCapture(Level.INFO);
540         byte val = 42;
541         LogSF.info(logger, "Iteration {}", val);
542         assertEquals("Iteration 42", capture.getMessage());
543     }
544 
545     /***
546      * Test LogSF.info with single field pattern with short argument.
547      */
548     public void testInfoShort() {
549         LogCapture capture = new LogCapture(Level.INFO);
550         short val = 42;
551         LogSF.info(logger, "Iteration {}", val);
552         assertEquals("Iteration 42", capture.getMessage());
553     }
554 
555     /***
556      * Test LogSF.info with single field pattern with long argument.
557      */
558     public void testInfoLong() {
559         LogCapture capture = new LogCapture(Level.INFO);
560         long val = 42;
561         LogSF.info(logger, "Iteration {}", val);
562         assertEquals("Iteration 42", capture.getMessage());
563     }
564 
565     /***
566      * Test LogSF.info with single field pattern with char argument.
567      */
568     public void testInfoChar() {
569         LogCapture capture = new LogCapture(Level.INFO);
570         char val = 'C';
571         LogSF.info(logger, "Iteration {}", val);
572         assertEquals("Iteration C", capture.getMessage());
573     }
574 
575     /***
576      * Test LogSF.info with single field pattern with boolean argument.
577      */
578     public void testInfoBoolean() {
579         LogCapture capture = new LogCapture(Level.INFO);
580         boolean val = true;
581         LogSF.info(logger, "Iteration {}", val);
582         assertEquals("Iteration true", capture.getMessage());
583     }
584 
585     /***
586      * Test LogSF.info with single field pattern with float argument.
587      */
588     public void testInfoFloat() {
589         LogCapture capture = new LogCapture(Level.INFO);
590         float val = 3.14f;
591         LogSF.info(logger, "Iteration {}", val);
592         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
593     }
594 
595     /***
596      * Test LogSF.info with single field pattern with double argument.
597      */
598     public void testInfoDouble() {
599         LogCapture capture = new LogCapture(Level.INFO);
600         double val = 3.14;
601         LogSF.info(logger, "Iteration {}", val);
602         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
603     }
604 
605     /***
606      * Test LogSF.info with two arguments.
607      */
608     public void testInfoTwoArg() {
609         LogCapture capture = new LogCapture(Level.INFO);
610         LogSF.info(logger, "{}, {}.", "Hello", "World");
611         assertEquals("Hello, World.", capture.getMessage());
612 
613     }
614 
615     /***
616      * Test LogSF.info with three arguments.
617      */
618     public void testInfoThreeArg() {
619         LogCapture capture = new LogCapture(Level.INFO);
620         LogSF.info(logger, "{}{} {}.", "Hello", ",", "World");
621         assertEquals("Hello, World.", capture.getMessage());
622     }
623 
624     /***
625      * Test LogSF.info with Object[] argument.
626      */
627     public void testInfoArrayArg() {
628         LogCapture capture = new LogCapture(Level.INFO);
629         Object[] args = new Object[] { "Hello", ",", "World", "." };
630         LogSF.info(logger, "{}{} {}{}", args);
631         assertEquals("Hello, World.", capture.getMessage());
632     }
633 
634     /***
635      * Test LogSF.warn with null pattern.
636      */
637     public void testWarnNullPattern() {
638         LogCapture capture = new LogCapture(Level.WARN);
639         LogSF.warn(logger, null, Math.PI);
640         assertNull(capture.getMessage());
641     }
642 
643     /***
644      * Test LogSF.warn with no-field pattern.
645      */
646     public void testWarnNoArg() {
647         LogCapture capture = new LogCapture(Level.WARN);
648         LogSF.warn(logger, "Hello, World", Math.PI);
649         assertEquals("Hello, World", capture.getMessage());
650     }
651 
652     /***
653      * Test LogSF.warn with malformed pattern.
654      */
655     public void testWarnBadPattern() {
656         LogCapture capture = new LogCapture(Level.WARN);
657         LogSF.warn(logger, "Hello, {.", Math.PI);
658         assertEquals("Hello, {.", capture.getMessage());
659     }
660 
661     /***
662      * Test LogSF.warn with missing argument.
663      */
664     public void testWarnMissingArg() {
665         LogCapture capture = new LogCapture(Level.WARN);
666         LogSF.warn(logger, "Hello, {}World", new Object[0]);
667         assertEquals("Hello, {}World", capture.getMessage());
668     }
669 
670     /***
671      * Test LogSF.warn with single field pattern with string argument.
672      */
673     public void testWarnString() {
674         LogCapture capture = new LogCapture(Level.WARN);
675         LogSF.warn(logger, "Hello, {}", "World");
676         assertEquals("Hello, World", capture.getMessage());
677     }
678 
679     /***
680      * Test LogSF.warn with single field pattern with null argument.
681      */
682     public void testWarnNull() {
683         LogCapture capture = new LogCapture(Level.WARN);
684         LogSF.warn(logger, "Hello, {}", (Object) null);
685         assertEquals("Hello, null", capture.getMessage());
686     }
687 
688     /***
689      * Test LogSF.warn with single field pattern with int argument.
690      */
691     public void testWarnInt() {
692         LogCapture capture = new LogCapture(Level.WARN);
693         int val = 42;
694         LogSF.warn(logger, "Iteration {}", val);
695         assertEquals("Iteration 42", capture.getMessage());
696     }
697 
698     /***
699      * Test LogSF.warn with single field pattern with byte argument.
700      */
701     public void testWarnByte() {
702         LogCapture capture = new LogCapture(Level.WARN);
703         byte val = 42;
704         LogSF.warn(logger, "Iteration {}", val);
705         assertEquals("Iteration 42", capture.getMessage());
706     }
707 
708     /***
709      * Test LogSF.warn with single field pattern with short argument.
710      */
711     public void testWarnShort() {
712         LogCapture capture = new LogCapture(Level.WARN);
713         short val = 42;
714         LogSF.warn(logger, "Iteration {}", val);
715         assertEquals("Iteration 42", capture.getMessage());
716     }
717 
718     /***
719      * Test LogSF.warn with single field pattern with long argument.
720      */
721     public void testWarnLong() {
722         LogCapture capture = new LogCapture(Level.WARN);
723         long val = 42;
724         LogSF.warn(logger, "Iteration {}", val);
725         assertEquals("Iteration 42", capture.getMessage());
726     }
727 
728     /***
729      * Test LogSF.warn with single field pattern with char argument.
730      */
731     public void testWarnChar() {
732         LogCapture capture = new LogCapture(Level.WARN);
733         char val = 'C';
734         LogSF.warn(logger, "Iteration {}", val);
735         assertEquals("Iteration C", capture.getMessage());
736     }
737 
738     /***
739      * Test LogSF.warn with single field pattern with boolean argument.
740      */
741     public void testWarnBoolean() {
742         LogCapture capture = new LogCapture(Level.WARN);
743         boolean val = true;
744         LogSF.warn(logger, "Iteration {}", val);
745         assertEquals("Iteration true", capture.getMessage());
746     }
747 
748     /***
749      * Test LogSF.warn with single field pattern with float argument.
750      */
751     public void testWarnFloat() {
752         LogCapture capture = new LogCapture(Level.WARN);
753         float val = 3.14f;
754         LogSF.warn(logger, "Iteration {}", val);
755         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
756     }
757 
758     /***
759      * Test LogSF.warn with single field pattern with double argument.
760      */
761     public void testWarnDouble() {
762         LogCapture capture = new LogCapture(Level.WARN);
763         double val = 3.14;
764         LogSF.warn(logger, "Iteration {}", val);
765         assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
766     }
767 
768     /***
769      * Test LogSF.warn with two arguments.
770      */
771     public void testWarnTwoArg() {
772         LogCapture capture = new LogCapture(Level.WARN);
773         LogSF.warn(logger, "{}, {}.", "Hello", "World");
774         assertEquals("Hello, World.", capture.getMessage());
775 
776     }
777 
778     /***
779      * Test LogSF.warn with three arguments.
780      */
781     public void testWarnThreeArg() {
782         LogCapture capture = new LogCapture(Level.WARN);
783         LogSF.warn(logger, "{}{} {}.", "Hello", ",", "World");
784         assertEquals("Hello, World.", capture.getMessage());
785     }
786 
787     /***
788      * Test LogSF.warn with Object[] argument.
789      */
790     public void testWarnFourArg() {
791         LogCapture capture = new LogCapture(Level.WARN);
792         LogSF.warn(logger, "{}{} {}{}",
793                  "Hello", ",", "World", "." );
794         assertEquals("Hello, World.", capture.getMessage());
795     }
796 
797     /***
798      * Test LogSF.warn with Object[] argument.
799      */
800     public void testWarnArrayArg() {
801         LogCapture capture = new LogCapture(Level.WARN);
802         Object[] args = new Object[] { "Hello", ",", "World", "." };
803         LogSF.warn(logger, "{}{} {}{}", args);
804         assertEquals("Hello, World.", capture.getMessage());
805     }
806 
807 
808     /***
809      * Test LogSF.log with null pattern.
810      */
811     public void testLogNullPattern() {
812         LogCapture capture = new LogCapture(Level.ERROR);
813         LogSF.log(logger, Level.ERROR, null, Math.PI);
814         assertNull(capture.getMessage());
815     }
816 
817     /***
818      * Test LogSF.log with no-field pattern.
819      */
820     public void testLogNoArg() {
821         LogCapture capture = new LogCapture(Level.ERROR);
822         LogSF.log(logger, Level.ERROR, "Hello, World", Math.PI);
823         assertEquals("Hello, World", capture.getMessage());
824     }
825 
826     /***
827      * Test LogSF.log with malformed pattern.
828      */
829     public void testLogBadPattern() {
830         LogCapture capture = new LogCapture(Level.ERROR);
831         LogSF.log(logger, Level.ERROR, "Hello, {.", Math.PI);
832         assertEquals("Hello, {.", capture.getMessage());
833     }
834 
835     /***
836      * Test LogSF.log with missing argument.
837      */
838     public void testLogMissingArg() {
839         LogCapture capture = new LogCapture(Level.ERROR);
840         LogSF.log(logger, Level.ERROR, "Hello, {}World", new Object[0]);
841         assertEquals("Hello, {}World", capture.getMessage());
842     }
843 
844     /***
845      * Test LogSF.log with single field pattern with string argument.
846      */
847     public void testLogString() {
848         LogCapture capture = new LogCapture(Level.ERROR);
849         LogSF.log(logger, Level.ERROR, "Hello, {}", "World");
850         assertEquals("Hello, World", capture.getMessage());
851     }
852 
853     /***
854      * Test LogSF.log with single field pattern with null argument.
855      */
856     public void testLogNull() {
857         LogCapture capture = new LogCapture(Level.ERROR);
858         LogSF.log(logger, Level.ERROR, "Hello, {}", (Object) null);
859         assertEquals("Hello, null", capture.getMessage());
860     }
861 
862     /***
863      * Test LogSF.log with single field pattern with int argument.
864      */
865     public void testLogInt() {
866         LogCapture capture = new LogCapture(Level.ERROR);
867         int val = 42;
868         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
869         assertEquals("Iteration 42", capture.getMessage());
870     }
871 
872     /***
873      * Test LogSF.log with single field pattern with byte argument.
874      */
875     public void testLogByte() {
876         LogCapture capture = new LogCapture(Level.ERROR);
877         byte val = 42;
878         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
879         assertEquals("Iteration 42", capture.getMessage());
880     }
881 
882     /***
883      * Test LogSF.log with single field pattern with short argument.
884      */
885     public void testLogShort() {
886         LogCapture capture = new LogCapture(Level.ERROR);
887         short val = 42;
888         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
889         assertEquals("Iteration 42", capture.getMessage());
890     }
891 
892     /***
893      * Test LogSF.log with single field pattern with long argument.
894      */
895     public void testLogLong() {
896         LogCapture capture = new LogCapture(Level.ERROR);
897         long val = 42;
898         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
899         assertEquals("Iteration 42", capture.getMessage());
900     }
901 
902     /***
903      * Test LogSF.log with single field pattern with char argument.
904      */
905     public void testLogChar() {
906         LogCapture capture = new LogCapture(Level.ERROR);
907         char val = 'C';
908         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
909         assertEquals("Iteration C", capture.getMessage());
910     }
911 
912     /***
913      * Test LogSF.log with single field pattern with boolean argument.
914      */
915     public void testLogBoolean() {
916         LogCapture capture = new LogCapture(Level.ERROR);
917         boolean val = true;
918         LogSF.log(logger, Level.ERROR, "Iteration {}", val);
919         assertEquals("Iteration true", capture.getMessage());
920     }
921 
922     /***
923      * Test LogSF.log with single field pattern with float argument.
924      */
925     public void testLogFloat() {
926         LogCapture capture = new LogCapture(Level.ERROR);
927         LogSF.log(logger, Level.ERROR, "Iteration {}", (float) Math.PI);
928 
929         String expected = "Iteration " + String.valueOf(new Float(Math.PI));
930         assertEquals(expected, capture.getMessage());
931     }
932 
933     /***
934      * Test LogSF.log with single field pattern with double argument.
935      */
936     public void testLogDouble() {
937         LogCapture capture = new LogCapture(Level.ERROR);
938         LogSF.log(logger, Level.ERROR, "Iteration {}", Math.PI);
939 
940         String expected = "Iteration " + String.valueOf(new Double(Math.PI));
941         assertEquals(expected, capture.getMessage());
942     }
943 
944     /***
945      * Test LogSF.log with two arguments.
946      */
947     public void testLogTwoArg() {
948         LogCapture capture = new LogCapture(Level.ERROR);
949         LogSF.log(logger, Level.ERROR, "{}, {}.", "Hello", "World");
950         assertEquals("Hello, World.", capture.getMessage());
951     }
952 
953     /***
954      * Test LogSF.log with three arguments.
955      */
956     public void testLogThreeArg() {
957         LogCapture capture = new LogCapture(Level.ERROR);
958         LogSF.log(logger, Level.ERROR, "{}{} {}.", "Hello", ",", "World");
959         assertEquals("Hello, World.", capture.getMessage());
960     }
961 
962     /***
963      * Test LogSF.log with four arguments.
964      */
965     public void testLogFourArg() {
966         LogCapture capture = new LogCapture(Level.ERROR);
967         LogSF.log(logger, Level.ERROR, "{}{} {}{}", "Hello", ",", "World", ".");
968         assertEquals("Hello, World.", capture.getMessage());
969     }
970 
971     /***
972      * Test LogSF.log with Object[] argument.
973      */
974     public void testLogArrayArg() {
975         LogCapture capture = new LogCapture(Level.ERROR);
976         Object[] args = new Object[] { "Hello", ",", "World", "." };
977         LogSF.log(logger, Level.ERROR, "{}{} {}{}", args);
978         assertEquals("Hello, World.", capture.getMessage());
979     }
980 
981     /***
982      * Bundle name for resource bundle tests.
983      */
984     private static final String BUNDLE_NAME =
985             "org.apache.log4j.TestLogSFPatterns";
986 
987     /***
988      * Test LogSF.logrb with null bundle name.
989      */
990     public void testLogrbNullBundle() {
991         LogCapture capture = new LogCapture(Level.ERROR);
992         LogSF.logrb(logger, Level.ERROR, null, "Iteration0", Math.PI);
993         assertEquals("Iteration0", capture.getMessage());
994     }
995 
996     /***
997      * Test LogSF.logrb with null key.
998      */
999     public void testLogrbNullKey() {
1000         LogCapture capture = new LogCapture(Level.ERROR);
1001         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, null, Math.PI);
1002         assertNull(capture.getMessage());
1003     }
1004 
1005     /***
1006      * Test LogSF.logrb with no-field pattern.
1007      */
1008     public void testLogrbNoArg() {
1009         LogCapture capture = new LogCapture(Level.ERROR);
1010         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello1", Math.PI);
1011         assertEquals("Hello, World", capture.getMessage());
1012     }
1013 
1014     /***
1015      * Test LogSF.logrb with malformed pattern.
1016      */
1017     public void testLogrbBadPattern() {
1018         LogCapture capture = new LogCapture(Level.ERROR);
1019         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Malformed", Math.PI);
1020         assertEquals("Hello, {.", capture.getMessage());
1021     }
1022 
1023     /***
1024      * Test LogSF.logrb with missing argument.
1025      */
1026     public void testLogrbMissingArg() {
1027         LogCapture capture = new LogCapture(Level.ERROR);
1028         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello2", new Object[0]);
1029         assertEquals("Hello, {}World", capture.getMessage());
1030     }
1031 
1032     /***
1033      * Test LogSF.logrb with single field pattern with string argument.
1034      */
1035     public void testLogrbString() {
1036         LogCapture capture = new LogCapture(Level.ERROR);
1037         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", "World");
1038         assertEquals("Hello, World", capture.getMessage());
1039     }
1040 
1041     /***
1042      * Test LogSF.logrb with single field pattern with null argument.
1043      */
1044     public void testLogrbNull() {
1045         LogCapture capture = new LogCapture(Level.ERROR);
1046         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", (Object) null);
1047         assertEquals("Hello, null", capture.getMessage());
1048     }
1049 
1050     /***
1051      * Test LogSF.logrb with single field pattern with int argument.
1052      */
1053     public void testLogrbInt() {
1054         LogCapture capture = new LogCapture(Level.ERROR);
1055         int val = 42;
1056         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1057         assertEquals("Iteration 42", capture.getMessage());
1058     }
1059 
1060     /***
1061      * Test LogSF.logrb with single field pattern with byte argument.
1062      */
1063     public void testLogrbByte() {
1064         LogCapture capture = new LogCapture(Level.ERROR);
1065         byte val = 42;
1066         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1067         assertEquals("Iteration 42", capture.getMessage());
1068     }
1069 
1070     /***
1071      * Test LogSF.logrb with single field pattern with short argument.
1072      */
1073     public void testLogrbShort() {
1074         LogCapture capture = new LogCapture(Level.ERROR);
1075         short val = 42;
1076         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1077         assertEquals("Iteration 42", capture.getMessage());
1078     }
1079 
1080     /***
1081      * Test LogSF.logrb with single field pattern with long argument.
1082      */
1083     public void testLogrbLong() {
1084         LogCapture capture = new LogCapture(Level.ERROR);
1085         long val = 42;
1086         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1087         assertEquals("Iteration 42", capture.getMessage());
1088     }
1089 
1090     /***
1091      * Test LogSF.logrb with single field pattern with char argument.
1092      */
1093     public void testLogrbChar() {
1094         LogCapture capture = new LogCapture(Level.ERROR);
1095         char val = 'C';
1096         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1097         assertEquals("Iteration C", capture.getMessage());
1098     }
1099 
1100     /***
1101      * Test LogSF.logrb with single field pattern with boolean argument.
1102      */
1103     public void testLogrbBoolean() {
1104         LogCapture capture = new LogCapture(Level.ERROR);
1105         boolean val = true;
1106         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
1107         assertEquals("Iteration true", capture.getMessage());
1108     }
1109 
1110     /***
1111      * Test LogSF.logrb with single field pattern with float argument.
1112      */
1113     public void testLogrbFloat() {
1114         LogCapture capture = new LogCapture(Level.ERROR);
1115         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME,
1116                 "Iteration0", (float) Math.PI);
1117 
1118         String expected = "Iteration " + String.valueOf(new Float(Math.PI));
1119         assertEquals(expected, capture.getMessage());
1120     }
1121 
1122     /***
1123      * Test LogSF.logrb with single field pattern with double argument.
1124      */
1125     public void testLogrbDouble() {
1126         LogCapture capture = new LogCapture(Level.ERROR);
1127         LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", Math.PI);
1128 
1129         String expected = "Iteration " + String.valueOf(new Double(Math.PI));
1130         assertEquals(expected, capture.getMessage());
1131     }
1132 
1133     /***
1134      * Test LogSF.logrb with two arguments.
1135      */
1136     public void testLogrbTwoArg() {
1137         LogCapture capture = new LogCapture(Level.ERROR);
1138         LogSF.logrb(logger, Level.ERROR,
1139                 BUNDLE_NAME, "Hello4", "Hello", "World");
1140         assertEquals("Hello, World.", capture.getMessage());
1141     }
1142 
1143     /***
1144      * Test LogSF.logrb with three arguments.
1145      */
1146     public void testLogrbThreeArg() {
1147         LogCapture capture = new LogCapture(Level.ERROR);
1148         LogSF.logrb(logger, Level.ERROR,
1149                 BUNDLE_NAME, "Hello5", "Hello", ",", "World");
1150         assertEquals("Hello, World.", capture.getMessage());
1151     }
1152 
1153     /***
1154      * Test LogSF.logrb with four arguments.
1155      */
1156     public void testLogrbFourArg() {
1157         LogCapture capture = new LogCapture(Level.ERROR);
1158         LogSF.logrb(logger, Level.ERROR,
1159                 BUNDLE_NAME, "Hello6", "Hello", ",", "World", ".");
1160         assertEquals("Hello, World.", capture.getMessage());
1161     }
1162 
1163     /***
1164      * Test LogSF.logrb with Object[] argument.
1165      */
1166     public void testLogrbArrayArg() {
1167         LogCapture capture = new LogCapture(Level.ERROR);
1168         Object[] args = new Object[] { "Hello", ",", "World", "." };
1169         LogSF.logrb(logger, Level.ERROR,
1170                 BUNDLE_NAME, "Hello6", args);
1171         assertEquals("Hello, World.", capture.getMessage());
1172     }
1173 
1174 }