15
15
*/
16
16
package org .owasp .esapi .reference .crypto ;
17
17
18
+ import static org .junit .Assert .*;
19
+
18
20
import java .io .*;
19
21
import java .util .Collection ;
20
22
import java .util .Enumeration ;
21
23
import java .util .Iterator ;
22
24
import java .util .Properties ;
23
25
24
- import junit .framework .Test ;
25
- import junit .framework .TestCase ;
26
- import junit .framework .TestSuite ;
27
-
26
+ import org .junit .Rule ;
27
+ import org .junit .Test ;
28
+ import org .junit .rules .TemporaryFolder ;
28
29
import org .owasp .esapi .errors .EncryptionException ;
29
30
import org .owasp .esapi .errors .EncryptionRuntimeException ;
30
31
35
36
* <a href="http://www.codemagi.com">CodeMagi, Inc.</a>
36
37
* @since October 8, 2010
37
38
*/
38
- public class ReferenceEncryptedPropertiesTest extends TestCase {
39
-
40
- /**
41
- * Instantiates a new encrypted properties test.
42
- *
43
- * @param testName
44
- * the test name
45
- */
46
- public ReferenceEncryptedPropertiesTest (String testName ) {
47
- super (testName );
48
- }
49
-
50
- /**
51
- * {@inheritDoc}
52
- */
53
- protected void setUp () throws Exception {
54
- // none
55
- }
56
-
57
- /**
58
- * {@inheritDoc}
59
- */
60
- protected void tearDown () throws Exception {
61
- // none
62
- }
63
-
64
- /**
65
- * Suite.
66
- *
67
- * @return the test
68
- */
69
- public static Test suite () {
70
- TestSuite suite = new TestSuite (ReferenceEncryptedPropertiesTest .class );
71
-
72
- return suite ;
73
- }
39
+ public class ReferenceEncryptedPropertiesTest {
74
40
41
+ @ Rule
42
+ public TemporaryFolder tempFolder = new TemporaryFolder ();
43
+
75
44
/**
76
45
* Test of getProperty method, of class org.owasp.esapi.EncryptedProperties.
77
46
*
78
47
* @throws EncryptionException
79
48
* the encryption exception
80
49
*/
81
- public void testGetProperty () throws EncryptionException {
50
+ @ Test public void testGetProperty () throws EncryptionException {
82
51
System .out .println ("getProperty" );
83
52
ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
84
53
String name = "name" ;
@@ -95,7 +64,7 @@ public void testGetProperty() throws EncryptionException {
95
64
* @throws EncryptionException
96
65
* the encryption exception
97
66
*/
98
- public void testSetProperty () throws EncryptionException {
67
+ @ Test public void testSetProperty () throws EncryptionException {
99
68
System .out .println ("setProperty" );
100
69
ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
101
70
String name = "name" ;
@@ -131,7 +100,7 @@ public void testSetProperty() throws EncryptionException {
131
100
/**
132
101
* Test the behavior when the requested key does not exist.
133
102
*/
134
- public void testNonExistantKeyValue () throws Exception
103
+ @ Test public void testNonExistantKeyValue () throws Exception
135
104
{
136
105
ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
137
106
assertNull (instance .getProperty ("not.there" ));
@@ -140,7 +109,7 @@ public void testNonExistantKeyValue() throws Exception
140
109
/**
141
110
* Test of keySet method, of class org.owasp.esapi.EncryptedProperties.
142
111
*/
143
- public void testKeySet () throws Exception
112
+ @ Test public void testKeySet () throws Exception
144
113
{
145
114
boolean sawTwo = false ;
146
115
boolean sawOne = false ;
@@ -175,7 +144,7 @@ else if(key.equals("two"))
175
144
/**
176
145
* Test storing and loading of encrypted properties.
177
146
*/
178
- public void testStoreLoad () throws Exception
147
+ @ Test public void testStoreLoad () throws Exception
179
148
{
180
149
ReferenceEncryptedProperties toLoad = new ReferenceEncryptedProperties ();
181
150
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
@@ -234,7 +203,7 @@ else if(key.equals("seuss.schneier"))
234
203
/**
235
204
* Test storing and loading of encrypted properties.
236
205
*/
237
- public void testStoreLoadWithReader () throws Exception
206
+ @ Test public void testStoreLoadWithReader () throws Exception
238
207
{
239
208
/*
240
209
//create an EncryptedProperties to store
@@ -300,7 +269,7 @@ else if(key.equals("seuss.schneier"))
300
269
/**
301
270
* Test overridden put method.
302
271
*/
303
- public void testPut () throws Exception
272
+ @ Test public void testPut () throws Exception
304
273
{
305
274
ReferenceEncryptedProperties props = new ReferenceEncryptedProperties ();
306
275
@@ -367,7 +336,7 @@ public void testPut() throws Exception
367
336
* Test that ReferenceEncryptedProperties can be properly constructed
368
337
* with an instance of Properties.
369
338
*/
370
- public void testConstructWithProperties () {
339
+ @ Test public void testConstructWithProperties () {
371
340
Properties props = new Properties ();
372
341
props .setProperty ("one" , "two" );
373
342
props .setProperty ("two" , "three" );
@@ -421,7 +390,7 @@ else if(key.equals("seuss.schneier"))
421
390
* Test that ReferenceEncryptedProperties can be properly constructed
422
391
* with an instance of EncryptedProperties.
423
392
*/
424
- public void testConstructWithEncryptedProperties () throws Exception {
393
+ @ Test public void testConstructWithEncryptedProperties () throws Exception {
425
394
ReferenceEncryptedProperties props = new ReferenceEncryptedProperties ();
426
395
props .setProperty ("one" , "two" );
427
396
props .setProperty ("two" , "three" );
@@ -475,13 +444,13 @@ else if(key.equals("seuss.schneier"))
475
444
/**
476
445
* Test overridden methods from Properties and Hashtable.
477
446
*/
478
- public void testOverriddenMethods () throws Exception {
447
+ @ Test public void testOverriddenMethods () throws Exception {
479
448
Properties props = new ReferenceEncryptedProperties ();
480
449
props .setProperty ("one" , "two" );
481
450
props .setProperty ("two" , "three" );
482
451
props .setProperty ("seuss.schneier" , "one fish, twofish, red fish, blowfish" );
483
452
484
- FileOutputStream out = new FileOutputStream ("ReferenceEncryptedProperties.test.txt" );
453
+ FileOutputStream out = new FileOutputStream (tempFolder . newFile ( "ReferenceEncryptedProperties.test.txt" ) );
485
454
PrintStream ps = new PrintStream (out );
486
455
try {
487
456
props .list (ps );
@@ -490,7 +459,7 @@ public void testOverriddenMethods() throws Exception {
490
459
assertTrue ( e instanceof UnsupportedOperationException );
491
460
}
492
461
493
- PrintWriter pw = new PrintWriter (new FileWriter ("test.out" ));
462
+ PrintWriter pw = new PrintWriter (new FileWriter (tempFolder . newFile ( "test.out" ) ));
494
463
try {
495
464
props .list (pw );
496
465
fail ("testOverriddenMethods(): list(PrintWriter) did not result in expected Exception" );
@@ -525,11 +494,6 @@ public void testOverriddenMethods() throws Exception {
525
494
} catch ( Exception e ) {
526
495
assertTrue ( e instanceof UnsupportedOperationException );
527
496
}
528
-
529
- File f1 = new File ("test.out" );
530
- f1 .delete ();
531
- File f = new File ("ReferenceEncryptedProperties.test.txt" );
532
- f .delete ();
533
497
}
534
498
535
499
}
0 commit comments