1515 */
1616package org .owasp .esapi .reference .crypto ;
1717
18+ import static org .junit .Assert .*;
19+
1820import java .io .*;
1921import java .util .Collection ;
2022import java .util .Enumeration ;
2123import java .util .Iterator ;
2224import java .util .Properties ;
2325
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 ;
2829import org .owasp .esapi .errors .EncryptionException ;
2930import org .owasp .esapi .errors .EncryptionRuntimeException ;
3031
3536 * <a href="http://www.codemagi.com">CodeMagi, Inc.</a>
3637 * @since October 8, 2010
3738 */
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 {
7440
41+ @ Rule
42+ public TemporaryFolder tempFolder = new TemporaryFolder ();
43+
7544 /**
7645 * Test of getProperty method, of class org.owasp.esapi.EncryptedProperties.
7746 *
7847 * @throws EncryptionException
7948 * the encryption exception
8049 */
81- public void testGetProperty () throws EncryptionException {
50+ @ Test public void testGetProperty () throws EncryptionException {
8251 System .out .println ("getProperty" );
8352 ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
8453 String name = "name" ;
@@ -95,7 +64,7 @@ public void testGetProperty() throws EncryptionException {
9564 * @throws EncryptionException
9665 * the encryption exception
9766 */
98- public void testSetProperty () throws EncryptionException {
67+ @ Test public void testSetProperty () throws EncryptionException {
9968 System .out .println ("setProperty" );
10069 ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
10170 String name = "name" ;
@@ -131,7 +100,7 @@ public void testSetProperty() throws EncryptionException {
131100 /**
132101 * Test the behavior when the requested key does not exist.
133102 */
134- public void testNonExistantKeyValue () throws Exception
103+ @ Test public void testNonExistantKeyValue () throws Exception
135104 {
136105 ReferenceEncryptedProperties instance = new ReferenceEncryptedProperties ();
137106 assertNull (instance .getProperty ("not.there" ));
@@ -140,7 +109,7 @@ public void testNonExistantKeyValue() throws Exception
140109 /**
141110 * Test of keySet method, of class org.owasp.esapi.EncryptedProperties.
142111 */
143- public void testKeySet () throws Exception
112+ @ Test public void testKeySet () throws Exception
144113 {
145114 boolean sawTwo = false ;
146115 boolean sawOne = false ;
@@ -175,7 +144,7 @@ else if(key.equals("two"))
175144 /**
176145 * Test storing and loading of encrypted properties.
177146 */
178- public void testStoreLoad () throws Exception
147+ @ Test public void testStoreLoad () throws Exception
179148 {
180149 ReferenceEncryptedProperties toLoad = new ReferenceEncryptedProperties ();
181150 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
@@ -234,7 +203,7 @@ else if(key.equals("seuss.schneier"))
234203 /**
235204 * Test storing and loading of encrypted properties.
236205 */
237- public void testStoreLoadWithReader () throws Exception
206+ @ Test public void testStoreLoadWithReader () throws Exception
238207 {
239208/*
240209 //create an EncryptedProperties to store
@@ -300,7 +269,7 @@ else if(key.equals("seuss.schneier"))
300269 /**
301270 * Test overridden put method.
302271 */
303- public void testPut () throws Exception
272+ @ Test public void testPut () throws Exception
304273 {
305274 ReferenceEncryptedProperties props = new ReferenceEncryptedProperties ();
306275
@@ -367,7 +336,7 @@ public void testPut() throws Exception
367336 * Test that ReferenceEncryptedProperties can be properly constructed
368337 * with an instance of Properties.
369338 */
370- public void testConstructWithProperties () {
339+ @ Test public void testConstructWithProperties () {
371340 Properties props = new Properties ();
372341 props .setProperty ("one" , "two" );
373342 props .setProperty ("two" , "three" );
@@ -421,7 +390,7 @@ else if(key.equals("seuss.schneier"))
421390 * Test that ReferenceEncryptedProperties can be properly constructed
422391 * with an instance of EncryptedProperties.
423392 */
424- public void testConstructWithEncryptedProperties () throws Exception {
393+ @ Test public void testConstructWithEncryptedProperties () throws Exception {
425394 ReferenceEncryptedProperties props = new ReferenceEncryptedProperties ();
426395 props .setProperty ("one" , "two" );
427396 props .setProperty ("two" , "three" );
@@ -475,13 +444,13 @@ else if(key.equals("seuss.schneier"))
475444 /**
476445 * Test overridden methods from Properties and Hashtable.
477446 */
478- public void testOverriddenMethods () throws Exception {
447+ @ Test public void testOverriddenMethods () throws Exception {
479448 Properties props = new ReferenceEncryptedProperties ();
480449 props .setProperty ("one" , "two" );
481450 props .setProperty ("two" , "three" );
482451 props .setProperty ("seuss.schneier" , "one fish, twofish, red fish, blowfish" );
483452
484- FileOutputStream out = new FileOutputStream ("ReferenceEncryptedProperties.test.txt" );
453+ FileOutputStream out = new FileOutputStream (tempFolder . newFile ( "ReferenceEncryptedProperties.test.txt" ) );
485454 PrintStream ps = new PrintStream (out );
486455 try {
487456 props .list (ps );
@@ -490,7 +459,7 @@ public void testOverriddenMethods() throws Exception {
490459 assertTrue ( e instanceof UnsupportedOperationException );
491460 }
492461
493- PrintWriter pw = new PrintWriter (new FileWriter ("test.out" ));
462+ PrintWriter pw = new PrintWriter (new FileWriter (tempFolder . newFile ( "test.out" ) ));
494463 try {
495464 props .list (pw );
496465 fail ("testOverriddenMethods(): list(PrintWriter) did not result in expected Exception" );
@@ -525,11 +494,6 @@ public void testOverriddenMethods() throws Exception {
525494 } catch ( Exception e ) {
526495 assertTrue ( e instanceof UnsupportedOperationException );
527496 }
528-
529- File f1 = new File ("test.out" );
530- f1 .delete ();
531- File f = new File ("ReferenceEncryptedProperties.test.txt" );
532- f .delete ();
533497 }
534498
535499}
0 commit comments