1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 import java.io.StringReader ; 31 import java.io.StringWriter ; 32 33 import junit.framework.Test; 34 import junit.framework.TestCase; 35 import junit.framework.TestSuite; 36 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 37 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 38 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 39 40 41 48 public class AnalysisModuleSetIOUTest extends TestCase 49 { 50 53 private static final Class THIS_CLASS = AnalysisModuleSetIOUTest.class; 54 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 55 56 public AnalysisModuleSetIOUTest( String name ) 57 { 58 super( name ); 59 } 60 61 62 65 public void testWriteAnalysisModuleSet1() throws Exception 66 { 67 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 68 StringWriter sw = new StringWriter (); 69 AnalysisModuleSet ams = new AnalysisModuleSet(); 70 71 amsio.writeAnalysisModuleSet( ams, sw ); 72 73 String res = sw.toString(); 74 DOC.getLog().info( "Wrote module set ["+res+"]" ); 75 assertEquals( 76 "Incorrect result format.", 77 "0{}", 78 res ); 79 } 80 81 public void testWriteAnalysisModuleSet2() throws Exception 82 { 83 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 84 StringWriter sw = new StringWriter (); 85 AnalysisModuleSet ams = createAnalysisModuleSet( 86 new IAnalysisModule[] { 87 createIAnalysisModule( "n", "u", "m" ), 88 } ); 89 90 amsio.writeAnalysisModuleSet( ams, sw ); 91 92 String res = sw.toString(); 93 DOC.getLog().info( "Wrote module set ["+res+"]" ); 94 assertEquals( 95 "Incorrect result format.", 96 "1{[0;11;1:n,1:u,1:m]}", 97 res ); 98 } 99 100 public void testWriteAnalysisModuleSet3() throws Exception 101 { 102 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 103 StringWriter sw = new StringWriter (); 104 AnalysisModuleSet ams = createAnalysisModuleSet( 105 new IAnalysisModule[] { 106 createIAnalysisModule( "n", "u", "m" ), 107 createIAnalysisModule( "", "", "" ), 108 createIAnalysisModule( "aaaa", "bbbb", "1234" ), 109 } ); 110 111 amsio.writeAnalysisModuleSet( ams, sw ); 112 113 String res = sw.toString(); 114 DOC.getLog().info( "Wrote module set ["+res+"]" ); 115 assertEquals( 116 "Incorrect result format.", 117 "3{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:][2;20;4:aaaa,4:bbbb,4:1234]}", 118 res ); 119 } 120 121 122 public void testReadAnalysisModuleSet1() throws Exception 123 { 124 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 125 StringReader sr = new StringReader ( "0{}" ); 126 AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr ); 127 IAnalysisModule[] amL = ams.getAnalysisModules(); 128 assertNotNull( 129 "Returned null data list.", 130 amL ); 131 assertEquals( 132 "Did not return an empty data set.", 133 0, 134 amL.length ); 135 } 136 137 138 public void testReadAnalysisModuleSet2() throws Exception 139 { 140 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 141 StringReader sr = new StringReader ( "1{[0;11;1:n,1:u,1:m]}" ); 142 AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr ); 143 IAnalysisModule[] amL = ams.getAnalysisModules(); 144 assertNotNull( 145 "Returned null data list.", 146 amL ); 147 assertEquals( 148 "Did not return an empty data set.", 149 1, 150 amL.length ); 151 IAnalysisModule am = amL[0]; 152 assertNotNull( 153 "Returned null module 0.", 154 am ); 155 assertEquals( 156 "name incorrect.", 157 "n", 158 am.getMeasureName() ); 159 assertEquals( 160 "unit incorrect.", 161 "u", 162 am.getMeasureUnit() ); 163 assertEquals( 164 "encoding incorrect.", 165 "m", 166 am.getMimeEncoding() ); 167 } 168 169 170 public void testReadAnalysisModuleSet3() throws Exception 171 { 172 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 173 StringReader sr = new StringReader ( 174 "2{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:]}" ); 175 AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr ); 176 IAnalysisModule[] amL = ams.getAnalysisModules(); 177 assertNotNull( 178 "Returned null data list.", 179 amL ); 180 assertEquals( 181 "Did not return an empty data set.", 182 2, 183 amL.length ); 184 185 IAnalysisModule am = amL[0]; 186 assertNotNull( 187 "Returned null module 0.", 188 am ); 189 assertEquals( 190 "0: name incorrect.", 191 "n", 192 am.getMeasureName() ); 193 assertEquals( 194 "0: unit incorrect.", 195 "u", 196 am.getMeasureUnit() ); 197 assertEquals( 198 "0: encoding incorrect.", 199 "m", 200 am.getMimeEncoding() ); 201 202 am = amL[1]; 203 assertNotNull( 204 "Returned null module 1.", 205 am ); 206 assertEquals( 207 "1: name incorrect.", 208 "", 209 am.getMeasureName() ); 210 assertEquals( 211 "1: unit incorrect.", 212 "", 213 am.getMeasureUnit() ); 214 assertEquals( 215 "1: encoding incorrect.", 216 "", 217 am.getMimeEncoding() ); 218 } 219 220 221 public void testReadAnalysisModuleSet4() throws Exception 222 { 223 AnalysisModuleSetIO amsio = new AnalysisModuleSetIO(); 224 StringReader sr = new StringReader ( 225 "{}" ); 226 try 227 { 228 amsio.readAnalysisModuleSet( sr ); 229 fail( "Did not throw IOException." ); 230 } 231 catch (IOException ioe) 232 { 233 } 235 } 236 237 238 241 protected AnalysisModuleSet createAnalysisModuleSet( IAnalysisModule amL[] ) 242 { 243 return CCCreatorUtil.createAnalysisModuleSet( amL ); 244 } 245 246 protected IAnalysisModule createIAnalysisModule( String name, String unit, 247 String mime ) 248 { 249 return CCCreatorUtil.createIAnalysisModule( name, unit, mime ); 250 } 251 252 253 256 257 public static Test suite() 258 { 259 TestSuite suite = new TestSuite( THIS_CLASS ); 260 261 return suite; 262 } 263 264 public static void main( String [] args ) 265 { 266 String [] name = { THIS_CLASS.getName() }; 267 268 271 junit.textui.TestRunner.main( name ); 272 } 273 274 275 279 protected void setUp() throws Exception 280 { 281 super.setUp(); 282 283 284 } 286 287 288 292 protected void tearDown() throws Exception 293 { 294 296 297 super.tearDown(); 298 } 299 } 300 301 | Popular Tags |