~ubuntu-branches/ubuntu/saucy/commons-configuration/saucy

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-07-01 16:29:44 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130701162944-98waq5gogha5gpn1
Tags: 1.9-1
* New upstream release
* debian/control:
  - Updated Standards-Version to 3.9.4 (no changes)
  - Use canonical URLs for the Vcs-* fields
  - Added new build dependencies (libjavacc-maven-plugin-java, junit4)
  - Upgraded the dependency on the Servlet API (2.5 -> 3.0)
  - Removed the dependency on the Activation Framework (glassfish-activation)
  - Replaced the dependency on glassfish-mail with libgnumail-java
  - Removed the unused dependencies:
    liblog4j1.2-java-doc, libmaven-assembly-plugin-java
  - Replaced the dependency on libcommons-jexl-java by libcommons-jexl2-java
* debian/watch: Changed to point the official Apache distribution server
* Removed the obsolete file debian/ant.properties
* Installed the upstream changelog in the binary packages
* Added the report plugins to maven.ignoreRules
* Added the classpath attribute to the jar manifest

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
18
 
package org.apache.commons.configuration;
19
 
 
20
 
import java.io.BufferedReader;
21
 
import java.io.File;
22
 
import java.io.FileOutputStream;
23
 
import java.io.FileReader;
24
 
import java.io.FileWriter;
25
 
import java.io.IOException;
26
 
import java.io.InputStream;
27
 
import java.io.OutputStream;
28
 
import java.io.PrintWriter;
29
 
import java.io.Reader;
30
 
import java.io.StringReader;
31
 
import java.io.StringWriter;
32
 
import java.io.Writer;
33
 
import java.net.HttpURLConnection;
34
 
import java.net.URL;
35
 
import java.net.URLConnection;
36
 
import java.net.URLStreamHandler;
37
 
import java.util.ArrayList;
38
 
import java.util.HashSet;
39
 
import java.util.Iterator;
40
 
import java.util.List;
41
 
import java.util.Set;
42
 
 
43
 
import junit.framework.TestCase;
44
 
 
45
 
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
46
 
import org.apache.commons.lang.SystemUtils;
47
 
 
48
 
/**
49
 
 * Test for loading and saving properties files.
50
 
 *
51
 
 * @version $Id: TestPropertiesConfiguration.java 951878 2010-06-06 15:56:47Z oheger $
52
 
 */
53
 
public class TestPropertiesConfiguration extends TestCase
54
 
{
55
 
    /** Constant for a test property name.*/
56
 
    private static final String PROP_NAME = "testProperty";
57
 
 
58
 
    /** Constant for a test property value.*/
59
 
    private static final String PROP_VALUE = "value";
60
 
 
61
 
    /** The configuration to be tested.*/
62
 
    private PropertiesConfiguration conf;
63
 
 
64
 
    /** The File that we test with */
65
 
    private static String testProperties = new File("conf/test.properties").getAbsolutePath();
66
 
 
67
 
    private static String testBasePath = new File("conf").getAbsolutePath();
68
 
    private static String testBasePath2 = new File("conf").getAbsoluteFile().getParentFile().getAbsolutePath();
69
 
    private static File testSavePropertiesFile = new File("target/testsave.properties");
70
 
 
71
 
    protected void setUp() throws Exception
72
 
    {
73
 
        conf = new PropertiesConfiguration(testProperties);
74
 
 
75
 
        // remove the test save file if it exists
76
 
        if (testSavePropertiesFile.exists())
77
 
        {
78
 
            assertTrue("Test output file could not be deleted",
79
 
                    testSavePropertiesFile.delete());
80
 
        }
81
 
    }
82
 
 
83
 
    public void testLoad() throws Exception
84
 
    {
85
 
        String loaded = conf.getString("configuration.loaded");
86
 
        assertEquals("true", loaded);
87
 
    }
88
 
 
89
 
    /**
90
 
     * Tests if properties can be appended by simply calling load() another
91
 
     * time.
92
 
     */
93
 
    public void testAppend() throws Exception
94
 
    {
95
 
        File file2 = new File("conf/threesome.properties");
96
 
        conf.load(file2);
97
 
        assertEquals("aaa", conf.getString("test.threesome.one"));
98
 
        assertEquals("true", conf.getString("configuration.loaded"));
99
 
    }
100
 
 
101
 
    /**
102
 
     * Tests that empty properties are treated as the empty string
103
 
     * (rather than as null).
104
 
     */
105
 
    public void testEmpty() throws Exception
106
 
    {
107
 
        String empty = conf.getString("test.empty");
108
 
        assertNotNull(empty);
109
 
        assertEquals("", empty);
110
 
    }
111
 
 
112
 
    /**
113
 
     * Tests that references to other properties work
114
 
     */
115
 
    public void testReference() throws Exception
116
 
    {
117
 
        assertEquals("baseextra", conf.getString("base.reference"));
118
 
    }
119
 
 
120
 
    /**
121
 
     * test if includes properties get loaded too
122
 
     */
123
 
    public void testLoadInclude() throws Exception
124
 
    {
125
 
        String loaded = conf.getString("include.loaded");
126
 
        assertEquals("true", loaded);
127
 
    }
128
 
 
129
 
    /**
130
 
     * test if includes properties from interpolated file
131
 
     * name get loaded
132
 
     */
133
 
    public void testLoadIncludeInterpol() throws Exception
134
 
    {
135
 
        String loaded = conf.getString("include.interpol.loaded");
136
 
        assertEquals("true", loaded);
137
 
    }
138
 
 
139
 
    public void testSetInclude() throws Exception
140
 
    {
141
 
        // change the include key
142
 
        PropertiesConfiguration.setInclude("import");
143
 
 
144
 
        // load the configuration
145
 
        PropertiesConfiguration conf = new PropertiesConfiguration();
146
 
        conf.load("conf/test.properties");
147
 
 
148
 
        // restore the previous value for the other tests
149
 
        PropertiesConfiguration.setInclude("include");
150
 
 
151
 
        assertNull(conf.getString("include.loaded"));
152
 
    }
153
 
 
154
 
    /**
155
 
     * Tests <code>List</code> parsing.
156
 
     */
157
 
    public void testList() throws Exception
158
 
    {
159
 
        List packages = conf.getList("packages");
160
 
        // we should get 3 packages here
161
 
        assertEquals(3, packages.size());
162
 
    }
163
 
 
164
 
    public void testSave() throws Exception
165
 
    {
166
 
        // add an array of strings to the configuration
167
 
        conf.addProperty("string", "value1");
168
 
        List list = new ArrayList();
169
 
        for (int i = 1; i < 5; i++)
170
 
        {
171
 
            list.add("value" + i);
172
 
        }
173
 
        conf.addProperty("array", list);
174
 
 
175
 
        // save the configuration
176
 
        String filename = testSavePropertiesFile.getAbsolutePath();
177
 
        conf.save(filename);
178
 
 
179
 
        assertTrue("The saved file doesn't exist", testSavePropertiesFile.exists());
180
 
 
181
 
        // read the configuration and compare the properties
182
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(filename);
183
 
        ConfigurationAssert.assertEquals(conf, checkConfig);
184
 
 
185
 
        // Save it again, verifing a save with a filename works.
186
 
        checkConfig.save();
187
 
    }
188
 
 
189
 
    public void testSaveToCustomURL() throws Exception
190
 
    {
191
 
        // save the configuration to a custom URL
192
 
        URL url = new URL("foo", "", 0, "./target/testsave-custom-url.properties", new FileURLStreamHandler());
193
 
        conf.save(url);
194
 
 
195
 
        // reload the configuration
196
 
        Configuration config2 = new PropertiesConfiguration(url);
197
 
        assertEquals("true", config2.getString("configuration.loaded"));
198
 
    }
199
 
 
200
 
    public void testInMemoryCreatedSave() throws Exception
201
 
    {
202
 
        PropertiesConfiguration pc = new PropertiesConfiguration();
203
 
        // add an array of strings to the configuration
204
 
        pc.addProperty("string", "value1");
205
 
        List list = new ArrayList();
206
 
        for (int i = 1; i < 5; i++)
207
 
        {
208
 
            list.add("value" + i);
209
 
        }
210
 
        pc.addProperty("array", list);
211
 
 
212
 
        // save the configuration
213
 
        String filename = testSavePropertiesFile.getAbsolutePath();
214
 
        pc.save(filename);
215
 
 
216
 
        assertTrue("The saved file doesn't exist", testSavePropertiesFile.exists());
217
 
 
218
 
        // read the configuration and compare the properties
219
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(filename);
220
 
        ConfigurationAssert.assertEquals(pc, checkConfig);
221
 
 
222
 
        // Save it again, verifing a save with a filename works.
223
 
        checkConfig.save();
224
 
    }
225
 
 
226
 
    /**
227
 
     * Tests saving a configuration when delimiter parsing is disabled.
228
 
     */
229
 
    public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException
230
 
    {
231
 
        conf.clear();
232
 
        conf.setDelimiterParsingDisabled(true);
233
 
        conf.addProperty("test.list", "a,b,c");
234
 
        conf.addProperty("test.dirs", "C:\\Temp\\,D:\\Data\\");
235
 
        conf.save(testSavePropertiesFile);
236
 
 
237
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration();
238
 
        checkConfig.setDelimiterParsingDisabled(true);
239
 
        checkConfig.setFile(testSavePropertiesFile);
240
 
        checkConfig.load();
241
 
        ConfigurationAssert.assertEquals(conf, checkConfig);
242
 
    }
243
 
 
244
 
    public void testSaveMissingFilename()
245
 
    {
246
 
        PropertiesConfiguration pc = new PropertiesConfiguration();
247
 
        try
248
 
        {
249
 
            pc.save();
250
 
            fail("Should have throw ConfigurationException");
251
 
        }
252
 
        catch (ConfigurationException ce)
253
 
        {
254
 
            //good
255
 
        }
256
 
    }
257
 
 
258
 
    /**
259
 
     * Tests if the base path is taken into account by the save() method.
260
 
     * @throws Exception if an error occurs
261
 
     */
262
 
    public void testSaveWithBasePath() throws Exception
263
 
    {
264
 
        conf.setProperty("test", "true");
265
 
        conf.setBasePath(testSavePropertiesFile.getParentFile().toURI().toURL()
266
 
                .toString());
267
 
        conf.setFileName(testSavePropertiesFile.getName());
268
 
        conf.save();
269
 
        assertTrue(testSavePropertiesFile.exists());
270
 
    }
271
 
 
272
 
    /**
273
 
     * Tests whether the escape character for list delimiters can be itself
274
 
     * escaped and survives a save operation.
275
 
     */
276
 
    public void testSaveEscapedEscapingCharacter()
277
 
            throws ConfigurationException
278
 
    {
279
 
        conf.addProperty("test.dirs", "C:\\Temp\\\\,D:\\Data\\\\,E:\\Test\\");
280
 
        List dirs = conf.getList("test.dirs");
281
 
        assertEquals("Wrong number of list elements", 3, dirs.size());
282
 
        conf.save(testSavePropertiesFile);
283
 
 
284
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(
285
 
                testSavePropertiesFile);
286
 
        ConfigurationAssert.assertEquals(conf, checkConfig);
287
 
    }
288
 
 
289
 
    public void testLoadViaProperty() throws Exception
290
 
    {
291
 
        PropertiesConfiguration pc = new PropertiesConfiguration();
292
 
        pc.setFileName(testProperties);
293
 
        pc.load();
294
 
 
295
 
        assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean"));
296
 
    }
297
 
 
298
 
    public void testLoadViaPropertyWithBasePath() throws Exception
299
 
    {
300
 
        PropertiesConfiguration pc = new PropertiesConfiguration();
301
 
        pc.setBasePath(testBasePath);
302
 
        pc.setFileName("test.properties");
303
 
        pc.load();
304
 
 
305
 
        assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean"));
306
 
    }
307
 
 
308
 
    public void testLoadViaPropertyWithBasePath2() throws Exception
309
 
    {
310
 
        PropertiesConfiguration pc = new PropertiesConfiguration();
311
 
        pc.setBasePath(testBasePath2);
312
 
        pc.setFileName("conf/test.properties");
313
 
        pc.load();
314
 
 
315
 
        assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean"));
316
 
 
317
 
        pc = new PropertiesConfiguration();
318
 
        pc.setBasePath(testBasePath2);
319
 
        pc.setFileName("conf/test.properties");
320
 
        pc.load();
321
 
 
322
 
        assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean"));
323
 
    }
324
 
 
325
 
    public void testLoadFromFile() throws Exception
326
 
    {
327
 
        File file = new File("conf/test.properties");
328
 
        conf = new PropertiesConfiguration(file);
329
 
 
330
 
        assertEquals("true", conf.getString("configuration.loaded"));
331
 
    }
332
 
 
333
 
    public void testLoadUnexistingFile()
334
 
    {
335
 
        try
336
 
        {
337
 
            conf = new PropertiesConfiguration("Unexisting file");
338
 
            fail("Unexisting file was loaded.");
339
 
        }
340
 
        catch(ConfigurationException cex)
341
 
        {
342
 
            // fine
343
 
        }
344
 
    }
345
 
 
346
 
    /**
347
 
     * Tests to load a file with enabled auto save mode.
348
 
     */
349
 
    public void testLoadWithAutoSave() throws Exception
350
 
    {
351
 
        setUpSavedProperties();
352
 
    }
353
 
 
354
 
    /**
355
 
     * Tests the auto save functionality when an existing property is modified.
356
 
     */
357
 
    public void testLoadWithAutoSaveAndSetExisting() throws Exception
358
 
    {
359
 
        setUpSavedProperties();
360
 
        conf.setProperty("a", "moreThanOne");
361
 
        checkSavedConfig();
362
 
    }
363
 
 
364
 
    /**
365
 
     * Tests the auto save functionality when a new property is added using the
366
 
     * setProperty() method.
367
 
     */
368
 
    public void testLoadWithAutoSaveAndSetNew() throws Exception
369
 
    {
370
 
        setUpSavedProperties();
371
 
        conf.setProperty("d", "four");
372
 
        checkSavedConfig();
373
 
    }
374
 
 
375
 
    /**
376
 
     * Tests the auto save functionality when a new property is added using the
377
 
     * addProperty() method.
378
 
     */
379
 
    public void testLoadWithAutoSaveAndAdd() throws Exception
380
 
    {
381
 
        setUpSavedProperties();
382
 
        conf.addProperty("d", "four");
383
 
        checkSavedConfig();
384
 
    }
385
 
 
386
 
    /**
387
 
     * Tests the auto save functionality when a property is removed.
388
 
     */
389
 
    public void testLoadWithAutoSaveAndClear() throws Exception
390
 
    {
391
 
        setUpSavedProperties();
392
 
        conf.clearProperty("c");
393
 
        PropertiesConfiguration checkConfig = checkSavedConfig();
394
 
        assertFalse("The saved configuration contain the key '" + "c" + "'", checkConfig.containsKey("c"));
395
 
    }
396
 
 
397
 
    /**
398
 
     * Creates a properties file on disk. Used for testing load and save
399
 
     * operations.
400
 
     *
401
 
     * @throws IOException if an I/O error occurs
402
 
     */
403
 
    private void setUpSavedProperties() throws IOException, ConfigurationException
404
 
    {
405
 
        PrintWriter out = null;
406
 
 
407
 
        try
408
 
        {
409
 
            out = new PrintWriter(new FileWriter(testSavePropertiesFile));
410
 
            out.println("a = one");
411
 
            out.println("b = two");
412
 
            out.println("c = three");
413
 
            out.close();
414
 
            out = null;
415
 
 
416
 
            conf = new PropertiesConfiguration();
417
 
            conf.setAutoSave(true);
418
 
            conf.setFile(testSavePropertiesFile);
419
 
            conf.load();
420
 
            assertEquals("one", conf.getString("a"));
421
 
            assertEquals("two", conf.getString("b"));
422
 
            assertEquals("three", conf.getString("c"));
423
 
        }
424
 
        finally
425
 
        {
426
 
            if (out != null)
427
 
            {
428
 
                out.close();
429
 
            }
430
 
        }
431
 
    }
432
 
 
433
 
    /**
434
 
     * Helper method for testing a saved configuration. Reads in the file using
435
 
     * a new instance and compares this instance with the original one.
436
 
     *
437
 
     * @return the newly created configuration instance
438
 
     * @throws ConfigurationException if an error occurs
439
 
     */
440
 
    private PropertiesConfiguration checkSavedConfig()
441
 
            throws ConfigurationException
442
 
    {
443
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(testSavePropertiesFile);
444
 
        ConfigurationAssert.assertEquals(conf, checkConfig);
445
 
        return checkConfig;
446
 
    }
447
 
 
448
 
    public void testGetStringWithEscapedChars()
449
 
    {
450
 
        String property = conf.getString("test.unescape");
451
 
        assertEquals("String with escaped characters", "This \n string \t contains \" escaped \\ characters", property);
452
 
    }
453
 
 
454
 
    public void testGetStringWithEscapedComma()
455
 
    {
456
 
        String property = conf.getString("test.unescape.list-separator");
457
 
        assertEquals("String with an escaped list separator", "This string contains , an escaped list separator", property);
458
 
    }
459
 
 
460
 
    public void testUnescapeJava()
461
 
    {
462
 
        assertEquals("test\\,test", PropertiesConfiguration.unescapeJava("test\\,test", ','));
463
 
    }
464
 
 
465
 
    public void testEscapedKey() throws Exception
466
 
    {
467
 
        PropertiesConfiguration conf = new PropertiesConfiguration();
468
 
        conf.load(new StringReader("\\u0066\\u006f\\u006f=bar"));
469
 
 
470
 
        assertEquals("value of the 'foo' property", "bar", conf.getString("foo"));
471
 
    }
472
 
 
473
 
    public void testMixedArray()
474
 
    {
475
 
        String[] array = conf.getStringArray("test.mixed.array");
476
 
 
477
 
        assertEquals("array length", 4, array.length);
478
 
        assertEquals("1st element", "a", array[0]);
479
 
        assertEquals("2nd element", "b", array[1]);
480
 
        assertEquals("3rd element", "c", array[2]);
481
 
        assertEquals("4th element", "d", array[3]);
482
 
    }
483
 
 
484
 
    public void testMultilines()
485
 
    {
486
 
        String property = "This is a value spread out across several adjacent "
487
 
                + "natural lines by escaping the line terminator with "
488
 
                + "a backslash character.";
489
 
 
490
 
        assertEquals("'test.multilines' property", property, conf.getString("test.multilines"));
491
 
    }
492
 
 
493
 
    public void testChangingDefaultListDelimiter() throws Exception
494
 
    {
495
 
        PropertiesConfiguration pc = new PropertiesConfiguration(testProperties);
496
 
        assertEquals(4, pc.getList("test.mixed.array").size());
497
 
 
498
 
        char delimiter = PropertiesConfiguration.getDefaultListDelimiter();
499
 
        PropertiesConfiguration.setDefaultListDelimiter('^');
500
 
        pc = new PropertiesConfiguration(testProperties);
501
 
        assertEquals(2, pc.getList("test.mixed.array").size());
502
 
        PropertiesConfiguration.setDefaultListDelimiter(delimiter);
503
 
    }
504
 
 
505
 
    public void testChangingListDelimiter() throws Exception
506
 
    {
507
 
        PropertiesConfiguration pc1 = new PropertiesConfiguration(testProperties);
508
 
        assertEquals(4, pc1.getList("test.mixed.array").size());
509
 
 
510
 
        PropertiesConfiguration pc2 = new PropertiesConfiguration();
511
 
        pc2.setListDelimiter('^');
512
 
        pc2.setFileName(testProperties);
513
 
        pc2.load();
514
 
        assertEquals("Should obtain the first value", "a", pc2.getString("test.mixed.array"));
515
 
        assertEquals(2, pc2.getList("test.mixed.array").size());
516
 
    }
517
 
 
518
 
    public void testDisableListDelimiter() throws Exception
519
 
    {
520
 
        PropertiesConfiguration pc1 = new PropertiesConfiguration(testProperties);
521
 
        assertEquals(4, pc1.getList("test.mixed.array").size());
522
 
 
523
 
        PropertiesConfiguration pc2 = new PropertiesConfiguration();
524
 
        pc2.setDelimiterParsingDisabled(true);
525
 
        pc2.setFileName(testProperties);
526
 
        pc2.load();
527
 
        assertEquals(2, pc2.getList("test.mixed.array").size());
528
 
    }
529
 
 
530
 
    /**
531
 
     * Tests escaping of an end of line with a backslash.
532
 
     */
533
 
    public void testNewLineEscaping()
534
 
    {
535
 
        List list = conf.getList("test.path");
536
 
        assertEquals(3, list.size());
537
 
        assertEquals("C:\\path1\\", list.get(0));
538
 
        assertEquals("C:\\path2\\", list.get(1));
539
 
        assertEquals("C:\\path3\\complex\\test\\", list.get(2));
540
 
    }
541
 
 
542
 
    /**
543
 
     * Tests if included files are loaded when the source lies in the class path.
544
 
     */
545
 
    public void testLoadIncludeFromClassPath() throws ConfigurationException
546
 
    {
547
 
        conf = new PropertiesConfiguration("test.properties");
548
 
        assertEquals("true", conf.getString("include.loaded"));
549
 
    }
550
 
 
551
 
    /**
552
 
     * Test if the lines starting with # or ! are properly ignored.
553
 
     */
554
 
    public void testComment() {
555
 
        assertFalse("comment line starting with '#' parsed as a property", conf.containsKey("#comment"));
556
 
        assertFalse("comment line starting with '!' parsed as a property", conf.containsKey("!comment"));
557
 
    }
558
 
 
559
 
    /**
560
 
     * Check that key/value separators can be part of a key.
561
 
     */
562
 
    public void testEscapedKeyValueSeparator()
563
 
    {
564
 
        assertEquals("Escaped separator '=' not supported in keys", "foo", conf.getProperty("test.separator=in.key"));
565
 
        assertEquals("Escaped separator ':' not supported in keys", "bar", conf.getProperty("test.separator:in.key"));
566
 
        assertEquals("Escaped separator '\\t' not supported in keys", "foo", conf.getProperty("test.separator\tin.key"));
567
 
        assertEquals("Escaped separator '\\f' not supported in keys", "bar", conf.getProperty("test.separator\fin.key"));
568
 
        assertEquals("Escaped separator ' ' not supported in keys"  , "foo", conf.getProperty("test.separator in.key"));
569
 
    }
570
 
 
571
 
    /**
572
 
     * Test all acceptable key/value separators ('=', ':' or white spaces).
573
 
     */
574
 
    public void testKeyValueSeparators() {
575
 
        assertEquals("equal separator not properly parsed",      "foo", conf.getProperty("test.separator.equal"));
576
 
        assertEquals("colon separator not properly parsed",      "foo", conf.getProperty("test.separator.colon"));
577
 
        assertEquals("tab separator not properly parsed",        "foo", conf.getProperty("test.separator.tab"));
578
 
        assertEquals("formfeed separator not properly parsed",   "foo", conf.getProperty("test.separator.formfeed"));
579
 
        assertEquals("whitespace separator not properly parsed", "foo", conf.getProperty("test.separator.whitespace"));
580
 
    }
581
 
 
582
 
    /**
583
 
     * Tests including properties when they are loaded from a nested directory
584
 
     * structure.
585
 
     */
586
 
    public void testIncludeInSubDir() throws ConfigurationException
587
 
    {
588
 
        ConfigurationFactory factory = new ConfigurationFactory("conf/testFactoryPropertiesInclude.xml");
589
 
        Configuration config = factory.getConfiguration();
590
 
        assertEquals(true, config.getBoolean("deeptest"));
591
 
        assertEquals(true, config.getBoolean("deepinclude"));
592
 
        assertFalse(config.containsKey("deeptestinvalid"));
593
 
    }
594
 
 
595
 
    /**
596
 
     * Tests whether the correct line separator is used.
597
 
     */
598
 
    public void testLineSeparator() throws ConfigurationException
599
 
    {
600
 
        final String EOL = System.getProperty("line.separator");
601
 
        conf = new PropertiesConfiguration();
602
 
        conf.setHeader("My header");
603
 
        conf.setProperty("prop", "value");
604
 
 
605
 
        StringWriter out = new StringWriter();
606
 
        conf.save(out);
607
 
        String content = out.toString();
608
 
        assertTrue("Header could not be found", content.indexOf("# My header"
609
 
                + EOL + EOL) == 0);
610
 
        assertTrue("Property could not be found", content.indexOf("prop = value" + EOL) > 0);
611
 
    }
612
 
 
613
 
    /**
614
 
     * Tests what happens if a reloading strategy's <code>reloadingRequired()</code>
615
 
     * implementation accesses methods of the configuration that in turn cause a reload.
616
 
     */
617
 
    public void testReentrantReload()
618
 
    {
619
 
        conf.setProperty("shouldReload", Boolean.FALSE);
620
 
        conf.setReloadingStrategy(new FileChangedReloadingStrategy()
621
 
        {
622
 
            public boolean reloadingRequired()
623
 
            {
624
 
                return configuration.getBoolean("shouldReload");
625
 
            }
626
 
        });
627
 
        assertFalse("Property has wrong value", conf.getBoolean("shouldReload"));
628
 
    }
629
 
 
630
 
    /**
631
 
     * Tests accessing the layout object.
632
 
     */
633
 
    public void testGetLayout()
634
 
    {
635
 
        PropertiesConfigurationLayout layout = conf.getLayout();
636
 
        assertNotNull("Layout is null", layout);
637
 
        assertSame("Different object returned", layout, conf.getLayout());
638
 
        conf.setLayout(null);
639
 
        PropertiesConfigurationLayout layout2 = conf.getLayout();
640
 
        assertNotNull("Layout 2 is null", layout2);
641
 
        assertNotSame("Same object returned", layout, layout2);
642
 
    }
643
 
 
644
 
    /**
645
 
     * Tests the propertyLoaded() method for a simple property.
646
 
     */
647
 
    public void testPropertyLoaded() throws ConfigurationException
648
 
    {
649
 
        DummyLayout layout = new DummyLayout(conf);
650
 
        conf.setLayout(layout);
651
 
        conf.propertyLoaded("layoutLoadedProperty", "yes");
652
 
        assertEquals("Layout's load() was called", 0, layout.loadCalls);
653
 
        assertEquals("Property not added", "yes", conf.getString("layoutLoadedProperty"));
654
 
    }
655
 
 
656
 
    /**
657
 
     * Tests the propertyLoaded() method for an include property.
658
 
     */
659
 
    public void testPropertyLoadedInclude() throws ConfigurationException
660
 
    {
661
 
        DummyLayout layout = new DummyLayout(conf);
662
 
        conf.setLayout(layout);
663
 
        conf.propertyLoaded(PropertiesConfiguration.getInclude(), "testClasspath.properties,testEqual.properties");
664
 
        assertEquals("Layout's load() was not correctly called", 2, layout.loadCalls);
665
 
        assertFalse("Property was added", conf.containsKey(PropertiesConfiguration.getInclude()));
666
 
    }
667
 
 
668
 
    /**
669
 
     * Tests propertyLoaded() for an include property, when includes are
670
 
     * disabled.
671
 
     */
672
 
    public void testPropertyLoadedIncludeNotAllowed() throws ConfigurationException
673
 
    {
674
 
        DummyLayout layout = new DummyLayout(conf);
675
 
        conf.setLayout(layout);
676
 
        conf.setIncludesAllowed(false);
677
 
        conf.propertyLoaded(PropertiesConfiguration.getInclude(), "testClassPath.properties,testEqual.properties");
678
 
        assertEquals("Layout's load() was called", 0, layout.loadCalls);
679
 
        assertFalse("Property was added", conf.containsKey(PropertiesConfiguration.getInclude()));
680
 
    }
681
 
 
682
 
    /**
683
 
     * Tests whether comment lines are correctly detected.
684
 
     */
685
 
    public void testIsCommentLine()
686
 
    {
687
 
        assertTrue("Comment not detected", PropertiesConfiguration.isCommentLine("# a comment"));
688
 
        assertTrue("Alternative comment not detected", PropertiesConfiguration.isCommentLine("! a comment"));
689
 
        assertTrue("Comment with no space not detected", PropertiesConfiguration.isCommentLine("#a comment"));
690
 
        assertTrue("Comment with leading space not detected", PropertiesConfiguration.isCommentLine("    ! a comment"));
691
 
        assertFalse("Wrong comment", PropertiesConfiguration.isCommentLine("   a#comment"));
692
 
    }
693
 
 
694
 
    /**
695
 
     * Tests whether a properties configuration can be successfully cloned. It
696
 
     * is especially checked whether the layout object is taken into account.
697
 
     */
698
 
    public void testClone() throws ConfigurationException
699
 
    {
700
 
        PropertiesConfiguration copy = (PropertiesConfiguration) conf.clone();
701
 
        assertNotSame("Copy has same layout object", conf.getLayout(), copy.getLayout());
702
 
        assertEquals("Wrong number of event listeners for original", 1, conf.getConfigurationListeners().size());
703
 
        assertEquals("Wrong number of event listeners for clone", 1, copy.getConfigurationListeners().size());
704
 
        assertSame("Wrong event listener for original", conf.getLayout(), conf.getConfigurationListeners().iterator().next());
705
 
        assertSame("Wrong event listener for clone", copy.getLayout(), copy.getConfigurationListeners().iterator().next());
706
 
        StringWriter outConf = new StringWriter();
707
 
        conf.save(outConf);
708
 
        StringWriter outCopy = new StringWriter();
709
 
        copy.save(outCopy);
710
 
        assertEquals("Output from copy is different", outConf.toString(), outCopy.toString());
711
 
    }
712
 
 
713
 
    /**
714
 
     * Tests the clone() method when no layout object exists yet.
715
 
     */
716
 
    public void testCloneNullLayout()
717
 
    {
718
 
        conf = new PropertiesConfiguration();
719
 
        PropertiesConfiguration copy = (PropertiesConfiguration) conf.clone();
720
 
        assertNotSame("Layout objects are the same", conf.getLayout(), copy.getLayout());
721
 
    }
722
 
 
723
 
    /**
724
 
     * Tests saving a file-based configuration to a HTTP server.
725
 
     */
726
 
    public void testSaveToHTTPServerSuccess() throws Exception
727
 
    {
728
 
        MockHttpURLStreamHandler handler = new MockHttpURLStreamHandler(
729
 
                HttpURLConnection.HTTP_OK, testSavePropertiesFile);
730
 
        URL url = new URL(null, "http://jakarta.apache.org", handler);
731
 
        conf.save(url);
732
 
        MockHttpURLConnection con = handler.getMockConnection();
733
 
        assertTrue("Wrong output flag", con.getDoOutput());
734
 
        assertEquals("Wrong method", "PUT", con.getRequestMethod());
735
 
 
736
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(
737
 
                testSavePropertiesFile);
738
 
        ConfigurationAssert.assertEquals(conf, checkConfig);
739
 
    }
740
 
 
741
 
    /**
742
 
     * Tests saving a file-based configuration to a HTTP server when the server
743
 
     * reports a failure. This should cause an exception.
744
 
     */
745
 
    public void testSaveToHTTPServerFail() throws Exception
746
 
    {
747
 
        MockHttpURLStreamHandler handler = new MockHttpURLStreamHandler(
748
 
                HttpURLConnection.HTTP_BAD_REQUEST, testSavePropertiesFile);
749
 
        URL url = new URL(null, "http://jakarta.apache.org", handler);
750
 
        try
751
 
        {
752
 
            conf.save(url);
753
 
            fail("Response code was not checked!");
754
 
        }
755
 
        catch (ConfigurationException cex)
756
 
        {
757
 
            assertTrue("Wrong root cause: " + cex,
758
 
                    cex.getCause() instanceof IOException);
759
 
        }
760
 
    }
761
 
 
762
 
    /**
763
 
     * Test the creation of a file containing a '#' in its name. This test is
764
 
     * skipped on Java 1.3 as it always fails.
765
 
     */
766
 
    public void testFileWithSharpSymbol() throws Exception
767
 
    {
768
 
        if (SystemUtils.isJavaVersionAtLeast(1.4f))
769
 
        {
770
 
            File file = new File("target/sharp#1.properties");
771
 
            file.createNewFile();
772
 
 
773
 
            PropertiesConfiguration conf = new PropertiesConfiguration(file);
774
 
            conf.save();
775
 
 
776
 
            assertTrue("Missing file " + file, file.exists());
777
 
        }
778
 
    }
779
 
 
780
 
    /**
781
 
     * Tests initializing a properties configuration from a non existing file.
782
 
     * There was a bug, which caused properties getting lost when later save()
783
 
     * is called.
784
 
     */
785
 
    public void testInitFromNonExistingFile() throws ConfigurationException
786
 
    {
787
 
        final String testProperty = "test.successfull";
788
 
        conf = new PropertiesConfiguration(testSavePropertiesFile);
789
 
        conf.addProperty(testProperty, Boolean.TRUE);
790
 
        conf.save();
791
 
        PropertiesConfiguration checkConfig = new PropertiesConfiguration(
792
 
                testSavePropertiesFile);
793
 
        assertTrue("Test property not found", checkConfig
794
 
                .getBoolean(testProperty));
795
 
    }
796
 
 
797
 
    /**
798
 
     * Tests copying another configuration into the test configuration. This
799
 
     * test ensures that the layout object is informed about the newly added
800
 
     * properties.
801
 
     */
802
 
    public void testCopyAndSave() throws ConfigurationException
803
 
    {
804
 
        Configuration copyConf = setUpCopyConfig();
805
 
        conf.copy(copyConf);
806
 
        checkCopiedConfig(copyConf);
807
 
    }
808
 
 
809
 
    /**
810
 
     * Tests appending a configuration to the test configuration. Again it has
811
 
     * to be ensured that the layout object is correctly updated.
812
 
     */
813
 
    public void testAppendAndSave() throws ConfigurationException
814
 
    {
815
 
        Configuration copyConf = setUpCopyConfig();
816
 
        conf.append(copyConf);
817
 
        checkCopiedConfig(copyConf);
818
 
    }
819
 
 
820
 
    /**
821
 
     * Tests adding properties through a DataConfiguration. This is related to
822
 
     * CONFIGURATION-332.
823
 
     */
824
 
    public void testSaveWithDataConfig() throws ConfigurationException
825
 
    {
826
 
        conf = new PropertiesConfiguration(testSavePropertiesFile);
827
 
        DataConfiguration dataConfig = new DataConfiguration(conf);
828
 
        dataConfig.setProperty("foo", "bar");
829
 
        assertEquals("Property not set", "bar", conf.getString("foo"));
830
 
 
831
 
        conf.save();
832
 
        PropertiesConfiguration config2 = new PropertiesConfiguration(
833
 
                testSavePropertiesFile);
834
 
        assertEquals("Property not saved", "bar", config2.getString("foo"));
835
 
    }
836
 
 
837
 
    /**
838
 
     * Tests whether the correct default encoding is used when loading a
839
 
     * properties file. This test is related to CONFIGURATION-345.
840
 
     */
841
 
    public void testLoadWithDefaultEncoding() throws ConfigurationException
842
 
    {
843
 
        class PropertiesConfigurationTestImpl extends PropertiesConfiguration
844
 
        {
845
 
            String loadEncoding;
846
 
 
847
 
            public PropertiesConfigurationTestImpl(String fileName)
848
 
                    throws ConfigurationException
849
 
            {
850
 
                super(fileName);
851
 
            }
852
 
 
853
 
            public void load(InputStream in, String encoding)
854
 
                    throws ConfigurationException
855
 
            {
856
 
                loadEncoding = encoding;
857
 
                super.load(in, encoding);
858
 
            }
859
 
        }
860
 
 
861
 
        PropertiesConfigurationTestImpl testConf = new PropertiesConfigurationTestImpl(
862
 
                testProperties);
863
 
        assertEquals("Default encoding not used", "ISO-8859-1",
864
 
                testConf.loadEncoding);
865
 
    }
866
 
 
867
 
    /**
868
 
     * Tests whether a default IOFactory is set.
869
 
     */
870
 
    public void testGetIOFactoryDefault()
871
 
    {
872
 
        assertNotNull("No default IO factory", conf.getIOFactory());
873
 
    }
874
 
 
875
 
    /**
876
 
     * Tests setting the IOFactory to null. This should cause an exception.
877
 
     */
878
 
    public void testSetIOFactoryNull()
879
 
    {
880
 
        try
881
 
        {
882
 
            conf.setIOFactory(null);
883
 
            fail("Could set IO factory to null!");
884
 
        }
885
 
        catch (IllegalArgumentException iex)
886
 
        {
887
 
            // ok
888
 
        }
889
 
    }
890
 
 
891
 
    /**
892
 
     * Tests setting an IOFactory that uses a specialized reader.
893
 
     */
894
 
    public void testSetIOFactoryReader() throws ConfigurationException
895
 
    {
896
 
        final int propertyCount = 10;
897
 
        conf.clear();
898
 
        conf.setIOFactory(new PropertiesConfiguration.IOFactory()
899
 
        {
900
 
            public PropertiesConfiguration.PropertiesReader createPropertiesReader(
901
 
                    Reader in, char delimiter)
902
 
            {
903
 
                return new PropertiesReaderTestImpl(in, delimiter,
904
 
                        propertyCount);
905
 
            }
906
 
 
907
 
            public PropertiesConfiguration.PropertiesWriter createPropertiesWriter(
908
 
                    Writer out, char delimiter)
909
 
            {
910
 
                throw new UnsupportedOperationException("Unexpected call!");
911
 
            }
912
 
        });
913
 
        conf.load();
914
 
        for (int i = 1; i <= propertyCount; i++)
915
 
        {
916
 
            assertEquals("Wrong property value at " + i, PROP_VALUE + i, conf
917
 
                    .getString(PROP_NAME + i));
918
 
        }
919
 
    }
920
 
 
921
 
    /**
922
 
     * Tests setting an IOFactory that uses a specialized writer.
923
 
     */
924
 
    public void testSetIOFactoryWriter() throws ConfigurationException, IOException
925
 
    {
926
 
        final PropertiesWriterTestImpl testWriter = new PropertiesWriterTestImpl(',');
927
 
        conf.setIOFactory(new PropertiesConfiguration.IOFactory()
928
 
        {
929
 
            public PropertiesConfiguration.PropertiesReader createPropertiesReader(
930
 
                    Reader in, char delimiter)
931
 
            {
932
 
                throw new UnsupportedOperationException("Unexpected call!");
933
 
            }
934
 
 
935
 
            public PropertiesConfiguration.PropertiesWriter createPropertiesWriter(
936
 
                    Writer out, char delimiter)
937
 
            {
938
 
                return testWriter;
939
 
            }
940
 
        });
941
 
        conf.save(new StringWriter());
942
 
        testWriter.close();
943
 
        checkSavedConfig();
944
 
    }
945
 
 
946
 
    /**
947
 
     * Tests that the property separators are retained when saving the
948
 
     * configuration.
949
 
     */
950
 
    public void testKeepSeparators() throws ConfigurationException, IOException
951
 
    {
952
 
        conf.save(testSavePropertiesFile);
953
 
        final String[] separatorTests = {
954
 
                "test.separator.equal = foo", "test.separator.colon : foo",
955
 
                "test.separator.tab\tfoo", "test.separator.whitespace foo",
956
 
                "test.separator.no.space=foo"
957
 
        };
958
 
        Set foundLines = new HashSet();
959
 
        BufferedReader in = new BufferedReader(new FileReader(
960
 
                testSavePropertiesFile));
961
 
        try
962
 
        {
963
 
            String s;
964
 
            while ((s = in.readLine()) != null)
965
 
            {
966
 
                for (int i = 0; i < separatorTests.length; i++)
967
 
                {
968
 
                    if (separatorTests[i].equals(s))
969
 
                    {
970
 
                        foundLines.add(s);
971
 
                    }
972
 
                }
973
 
            }
974
 
        }
975
 
        finally
976
 
        {
977
 
            in.close();
978
 
        }
979
 
        assertEquals("No all separators were found: " + foundLines,
980
 
                separatorTests.length, foundLines.size());
981
 
    }
982
 
 
983
 
    /**
984
 
     * Tests whether properties with slashes in their values can be saved. This
985
 
     * test is related to CONFIGURATION-408.
986
 
     */
987
 
    public void testSlashEscaping() throws ConfigurationException
988
 
    {
989
 
        conf.setProperty(PROP_NAME, "http://www.apache.org");
990
 
        StringWriter writer = new StringWriter();
991
 
        conf.save(writer);
992
 
        String s = writer.toString();
993
 
        assertTrue("Value not found: " + s, s.indexOf(PROP_NAME
994
 
                + " = http://www.apache.org") >= 0);
995
 
    }
996
 
 
997
 
    /**
998
 
     * Tests whether backslashes are correctly handled if lists are parsed. This
999
 
     * test is related to CONFIGURATION-418.
1000
 
     */
1001
 
    public void testBackslashEscapingInLists() throws ConfigurationException
1002
 
    {
1003
 
        checkBackslashList("share2");
1004
 
        checkBackslashList("share1");
1005
 
    }
1006
 
 
1007
 
    /**
1008
 
     * Helper method for testing the content of a list with elements that
1009
 
     * contain backslashes.
1010
 
     *
1011
 
     * @param key the key
1012
 
     */
1013
 
    private void checkBackslashList(String key)
1014
 
    {
1015
 
        Object prop = conf.getProperty("test." + key);
1016
 
        assertTrue("Not a list", prop instanceof List);
1017
 
        List list = (List) prop;
1018
 
        assertEquals("Wrong number of list elements", 2, list.size());
1019
 
        final String prefix = "\\\\" + key;
1020
 
        assertEquals("Wrong element 1", prefix + "a", list.get(0));
1021
 
        assertEquals("Wrong element 2", prefix + "b", list.get(1));
1022
 
    }
1023
 
 
1024
 
    /**
1025
 
     * Creates a configuration that can be used for testing copy operations.
1026
 
     *
1027
 
     * @return the configuration to be copied
1028
 
     */
1029
 
    private Configuration setUpCopyConfig()
1030
 
    {
1031
 
        final int count = 25;
1032
 
        Configuration result = new BaseConfiguration();
1033
 
        for (int i = 1; i <= count; i++)
1034
 
        {
1035
 
            result.addProperty("copyKey" + i, "copyValue" + i);
1036
 
        }
1037
 
        return result;
1038
 
    }
1039
 
 
1040
 
    /**
1041
 
     * Tests whether the data of a configuration that was copied into the test
1042
 
     * configuration is correctly saved.
1043
 
     *
1044
 
     * @param copyConf the copied configuration
1045
 
     * @throws ConfigurationException if an error occurs
1046
 
     */
1047
 
    private void checkCopiedConfig(Configuration copyConf)
1048
 
            throws ConfigurationException
1049
 
    {
1050
 
        conf.save(testSavePropertiesFile);
1051
 
        PropertiesConfiguration checkConf = new PropertiesConfiguration(
1052
 
                testSavePropertiesFile);
1053
 
        for (Iterator it = copyConf.getKeys(); it.hasNext();)
1054
 
        {
1055
 
            String key = (String) it.next();
1056
 
            assertEquals("Wrong value for property " + key, checkConf
1057
 
                    .getProperty(key), copyConf.getProperty(key));
1058
 
        }
1059
 
    }
1060
 
 
1061
 
    /**
1062
 
     * A dummy layout implementation for checking whether certain methods are
1063
 
     * correctly called by the configuration.
1064
 
     */
1065
 
    static class DummyLayout extends PropertiesConfigurationLayout
1066
 
    {
1067
 
        /** Stores the number how often load() was called. */
1068
 
        public int loadCalls;
1069
 
 
1070
 
        public DummyLayout(PropertiesConfiguration config)
1071
 
        {
1072
 
            super(config);
1073
 
        }
1074
 
 
1075
 
        public void load(Reader in) throws ConfigurationException
1076
 
        {
1077
 
            loadCalls++;
1078
 
        }
1079
 
    }
1080
 
 
1081
 
    /**
1082
 
     * A mock implementation of a HttpURLConnection used for testing saving to
1083
 
     * a HTTP server.
1084
 
     */
1085
 
    static class MockHttpURLConnection extends HttpURLConnection
1086
 
    {
1087
 
        /** The response code to return.*/
1088
 
        private int responseCode;
1089
 
 
1090
 
        /** The output file. The output stream will point to this file.*/
1091
 
        private File outputFile;
1092
 
 
1093
 
        protected MockHttpURLConnection(URL u, int respCode, File outFile)
1094
 
        {
1095
 
            super(u);
1096
 
            responseCode = respCode;
1097
 
            outputFile = outFile;
1098
 
        }
1099
 
 
1100
 
        public void disconnect()
1101
 
        {
1102
 
        }
1103
 
 
1104
 
        public boolean usingProxy()
1105
 
        {
1106
 
            return false;
1107
 
        }
1108
 
 
1109
 
        public void connect() throws IOException
1110
 
        {
1111
 
        }
1112
 
 
1113
 
        public int getResponseCode() throws IOException
1114
 
        {
1115
 
            return responseCode;
1116
 
        }
1117
 
 
1118
 
        public OutputStream getOutputStream() throws IOException
1119
 
        {
1120
 
            return new FileOutputStream(outputFile);
1121
 
        }
1122
 
    }
1123
 
 
1124
 
    /**
1125
 
     * A mock stream handler for working with the mock HttpURLConnection.
1126
 
     */
1127
 
    static class MockHttpURLStreamHandler extends URLStreamHandler
1128
 
    {
1129
 
        /** Stores the response code.*/
1130
 
        private int responseCode;
1131
 
 
1132
 
        /** Stores the output file.*/
1133
 
        private File outputFile;
1134
 
 
1135
 
        /** Stores the connection.*/
1136
 
        private MockHttpURLConnection connection;
1137
 
 
1138
 
        public MockHttpURLStreamHandler(int respCode, File outFile)
1139
 
        {
1140
 
            responseCode = respCode;
1141
 
            outputFile = outFile;
1142
 
        }
1143
 
 
1144
 
        public MockHttpURLConnection getMockConnection()
1145
 
        {
1146
 
            return connection;
1147
 
        }
1148
 
 
1149
 
        protected URLConnection openConnection(URL u) throws IOException
1150
 
        {
1151
 
            connection = new MockHttpURLConnection(u, responseCode, outputFile);
1152
 
            return connection;
1153
 
        }
1154
 
    }
1155
 
 
1156
 
    /**
1157
 
     * A test PropertiesReader for testing whether a custom reader can be
1158
 
     * injected. This implementation creates a configurable number of synthetic
1159
 
     * test properties.
1160
 
     */
1161
 
    private static class PropertiesReaderTestImpl extends
1162
 
            PropertiesConfiguration.PropertiesReader
1163
 
    {
1164
 
        /** The number of test properties to be created. */
1165
 
        private final int maxProperties;
1166
 
 
1167
 
        /** The current number of properties. */
1168
 
        private int propertyCount;
1169
 
 
1170
 
        public PropertiesReaderTestImpl(Reader reader, char listDelimiter,
1171
 
                int maxProps)
1172
 
        {
1173
 
            super(reader, listDelimiter);
1174
 
            assertEquals("Wrong list delimiter", ',', listDelimiter);
1175
 
            maxProperties = maxProps;
1176
 
        }
1177
 
 
1178
 
        public String getPropertyName()
1179
 
        {
1180
 
            return PROP_NAME + propertyCount;
1181
 
        }
1182
 
 
1183
 
        public String getPropertyValue()
1184
 
        {
1185
 
            return PROP_VALUE + propertyCount;
1186
 
        }
1187
 
 
1188
 
        public boolean nextProperty() throws IOException
1189
 
        {
1190
 
            propertyCount++;
1191
 
            return propertyCount <= maxProperties;
1192
 
        }
1193
 
    }
1194
 
 
1195
 
    /**
1196
 
     * A test PropertiesWriter for testing whether a custom writer can be
1197
 
     * injected. This implementation simply redirects all output into a test
1198
 
     * file.
1199
 
     */
1200
 
    private static class PropertiesWriterTestImpl extends
1201
 
            PropertiesConfiguration.PropertiesWriter
1202
 
    {
1203
 
        public PropertiesWriterTestImpl(char delimiter) throws IOException
1204
 
        {
1205
 
            super(new FileWriter(testSavePropertiesFile), delimiter);
1206
 
        }
1207
 
    }
1208
 
}