18 |
18 |
19 package com.nokia.mj.impl.storage; |
19 package com.nokia.mj.impl.storage; |
20 |
20 |
21 import com.nokia.mj.test.storage.utils.StorageSessionTestUtils; |
21 import com.nokia.mj.test.storage.utils.StorageSessionTestUtils; |
22 |
22 |
23 import com.nokia.mj.impl.installer.utils.InstallerMain; |
23 import com.nokia.mj.impl.rt.test.UnitTestSuiteCreator; |
24 import j2meunit.framework.Test; |
24 import j2meunit.framework.Test; |
25 import j2meunit.framework.TestCase; |
25 import j2meunit.framework.TestCase; |
26 import j2meunit.framework.TestMethod; |
26 import j2meunit.framework.TestMethod; |
27 import j2meunit.framework.TestSuite; |
27 import j2meunit.framework.TestSuite; |
28 |
28 |
29 /** |
29 /** |
30 * StorageAttirubte test cases. See test methods for test case details. |
30 * StorageAttirubte test cases. See test methods for test case details. |
31 */ |
31 */ |
32 public class TestStorageAttribute extends TestCase |
32 public class TestStorageAttribute extends TestCase |
33 implements InstallerMain, StorageNames |
33 implements UnitTestSuiteCreator, StorageNames |
34 { |
34 { |
35 /** |
|
36 * Directory for JavaStorage tests. |
|
37 */ |
|
38 private static final String iTestRoot = "./jstest"; |
|
39 |
|
40 /** |
|
41 * Directory for JavaStorage journal and temp files. |
|
42 */ |
|
43 private static final String iIsRoot = iTestRoot + "/js"; |
|
44 |
|
45 private StorageSession iSession = null; |
35 private StorageSession iSession = null; |
46 private StorageSessionTestUtils iJtu = null; |
36 private StorageSessionTestUtils iJtu = null; |
47 |
37 |
48 public void installerMain(String[] args) |
38 public TestSuite createTestSuite(String[] args) |
49 { |
39 { |
50 TestSuite suite = new TestSuite(this.getClass().getName()); |
40 TestSuite suite = new TestSuite(this.getClass().getName()); |
51 |
41 |
52 suite.addTest(new TestStorageAttribute("testNameValueConstructor", new TestMethod() |
42 suite.addTest(new TestStorageAttribute("testNameValueConstructor", new TestMethod() |
53 { |
43 { |
389 * 2. Test Name null throws StorageException |
379 * 2. Test Name null throws StorageException |
390 * 3. Test Name "" throws StorageException |
380 * 3. Test Name "" throws StorageException |
391 * 4. Test value null. If value is not set null is returned. |
381 * 4. Test value null. If value is not set null is returned. |
392 * 5. Test value "". |
382 * 5. Test value "". |
393 * 6. Test one len arguments. |
383 * 6. Test one len arguments. |
|
384 * 7. Test hashCode. |
|
385 * 8. Test instanceof true. |
|
386 * 9. Test instanceof false. |
394 */ |
387 */ |
395 public void testAttribute() |
388 public void testAttribute() |
396 { |
389 { |
397 StorageAttribute sa = new StorageAttribute("N/A", "N/A"); |
390 StorageAttribute sa = new StorageAttribute("N/A", "N/A"); |
398 |
391 |
485 } |
478 } |
486 catch (StorageException se) |
479 catch (StorageException se) |
487 { |
480 { |
488 assertTrue("Attribute set failed: " + se.getMessage(), false); |
481 assertTrue("Attribute set failed: " + se.getMessage(), false); |
489 } |
482 } |
|
483 |
|
484 // 7. Test hashCode. |
|
485 try |
|
486 { |
|
487 String name = "HashCode"; |
|
488 String value = "V"; |
|
489 sa.setAttribute(name, value, StorageAttribute.STRING_TYPE); |
|
490 |
|
491 assertTrue(sa.hashCode() > 0); |
|
492 } |
|
493 catch (StorageException se) |
|
494 { |
|
495 assertTrue("Attribute hashCode failed: " + se.getMessage(), false); |
|
496 } |
|
497 // 8. Test instanceof true and same. |
|
498 try |
|
499 { |
|
500 String name = "Instanceof"; |
|
501 String value = "V"; |
|
502 sa.setAttribute(name, value, StorageAttribute.STRING_TYPE); |
|
503 StorageAttribute sa2 = sa; |
|
504 assertTrue(sa.equals(sa2)); |
|
505 } |
|
506 catch (StorageException se) |
|
507 { |
|
508 assertTrue("Attribute equals same failed: " + se.getMessage(), false); |
|
509 } |
|
510 |
|
511 // 9. Test instanceof false. |
|
512 try |
|
513 { |
|
514 String name = "Instanceof"; |
|
515 assertTrue(!(sa.equals(name))); |
|
516 } |
|
517 catch (StorageException se) |
|
518 { |
|
519 assertTrue("Attribute equals instanceof failed: " + se.getMessage(), false); |
|
520 } |
|
521 |
|
522 // 10. Test equals false |
|
523 try |
|
524 { |
|
525 String name = "nottheSame"; |
|
526 String value = "V"; |
|
527 StorageAttribute sa2 = new StorageAttribute(name, value); |
|
528 assertTrue(!(sa.equals(sa2))); |
|
529 } |
|
530 catch (StorageException se) |
|
531 { |
|
532 assertTrue("Attribute equals instanceof failed: " + se.getMessage(), false); |
|
533 } |
|
534 |
490 } |
535 } |
491 |
536 |
492 /** |
537 /** |
493 * Test toString method. |
538 * Test toString method. |
494 * 1. Test with Name, Value and Type. |
539 * 1. Test with Name, Value and Type. |