~ubuntu-branches/ubuntu/quantal/simple-xml/quantal

« back to all changes in this revision

Viewing changes to test/src/org/simpleframework/xml/core/StrategyTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru, Fabian Köster
  • Date: 2010-03-05 19:44:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100305194434-d9mwhyioc9npo9it
Tags: 2.3.2-1
* Standards-Version updated to version 3.8.4

[ Fabian Köster ]
* New upstream release
* Correct license information in debian/pom.xml
* Exclude generated Javadoc from orig-tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
   }
52
52
 
53
53
   public class ExampleStrategy implements Strategy {
54
 
 
55
 
      public int writeRootCount = 0;           
56
 
 
57
 
      public int readRootCount = 0;
58
 
 
 
54
      
59
55
      private StrategyTest test;
60
56
 
61
57
      public ExampleStrategy(StrategyTest test){
62
58
         this.test = test;              
63
59
      }
64
60
 
65
 
      public Value getRoot(Type type, NodeMap root, Map map) throws Exception {
66
 
         readRootCount++;
67
 
         return getElement(type, root, map);              
68
 
      }
69
 
 
70
 
      public Value getElement(Type field, NodeMap node, Map map) throws Exception {
 
61
      public Value read(Type field, NodeMap node, Map map) throws Exception {
71
62
         Node value = node.remove(ELEMENT_NAME);
72
 
 
73
 
         if(readRootCount != 1) {
74
 
            test.assertTrue("Root must only be read once", false);                 
75
 
         }         
 
63
         
76
64
         if(value == null) {
77
65
                 return null;
78
66
         }
80
68
         Class type = Class.forName(name);
81
69
         
82
70
         return new SimpleType(type);
83
 
      }         
84
 
 
85
 
      public boolean setRoot(Type field, Object value, NodeMap root, Map map) throws Exception {                       
86
 
         writeRootCount++;              
87
 
         return setElement(field, value, root, map);              
88
 
      }              
89
 
 
90
 
      public boolean setElement(Type field, Object value, NodeMap node, Map map) throws Exception {
91
 
         if(writeRootCount != 1) {
92
 
            test.assertTrue("Root must be written only once", false);                 
93
 
         }                 
 
71
      }                      
 
72
 
 
73
      public boolean write(Type field, Object value, NodeMap node, Map map) throws Exception {            
94
74
         if(field.getType() != value.getClass()) {                       
95
75
            node.put(ELEMENT_NAME, value.getClass().getName());
96
76
         }  
144
124
      assertTrue(example instanceof ExampleExample);
145
125
      assertEquals(example.getValue(), "attribute-example-text");
146
126
      assertEquals(example.getKey(), "attribute-example-key");
147
 
      assertEquals(1, strategy.readRootCount);
148
 
      assertEquals(0, strategy.writeRootCount);
149
127
      
150
128
      persister.write(example, System.err);
151
 
      
152
 
      assertEquals(1, strategy.readRootCount);
153
 
      assertEquals(1, strategy.writeRootCount);
154
129
   }
155
130
}