Changeset 56 in tmcsimulator-scriptbuilder for trunk/test/scriptbuilder/structures
- Timestamp:
- 08/14/2017 12:35:16 PM (9 years ago)
- Location:
- trunk/test/scriptbuilder/structures
- Files:
-
- 7 added
- 1 edited
-
ScriptIncidentTest.java (modified) (3 diffs)
-
SimulationScriptTest.java (added)
-
TimeSliceTest.java (added)
-
XMLFormatIntegrationTest.java (added)
-
script.dtd (added)
-
single_incident_output_expected.xml (added)
-
test_input_file.xml (added)
-
test_output_file.xml (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/scriptbuilder/structures/ScriptIncidentTest.java
r13 r56 1 1 package scriptbuilder.structures; 2 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.nio.file.Files; 3 6 import java.util.ArrayList; 7 import static junit.framework.Assert.assertTrue; 4 8 import junit.framework.TestCase; 5 import static org.mockito.Matchers.*;9 import org.apache.commons.io.FileUtils; 6 10 import scriptbuilder.structures.events.*; 7 11 import static org.mockito.Mockito.*; … … 159 163 instance.setIncidentActive(); 160 164 verify(mockedScript, times(1)).broadcastEvent(isA(IncidentFocusedEvent.class)); 161 165 162 166 } 163 167 … … 176 180 } 177 181 182 /** 183 * Test of saveIncidentToFile method, of class ScriptIncident. 184 */ 185 public void testSaveIncidentToFile() 186 { 187 try 188 { 189 System.out.println("saveIncidentToFile"); 190 File inFile = new File("test/scriptbuilder/structures/test_input_file.xml"); 191 assertTrue(inFile.exists()); 192 File referenceFile = new File("test/scriptbuilder/structures/single_incident_output_expected.xml"); 193 assertTrue(referenceFile.exists()); 194 195 File outFile = new File("test/scriptbuilder/structures/test_output_file.xml"); 196 if (outFile.exists()) 197 { 198 outFile.delete(); 199 } 200 assertFalse(outFile.exists()); 201 outFile.createNewFile(); 202 assertTrue(outFile.exists()); 203 204 ScriptIncident instance = null; 205 SimulationScript script = new SimulationScript(); 206 script.loadScriptFromFile(inFile); 207 208 for (ScriptIncident inc : script.incidents) 209 { 210 if (inc != null && inc.number == 187) 211 { 212 instance = inc; 213 } 214 } 215 if (instance != null) 216 { 217 instance.saveIncidentToFile(outFile); 218 } 219 220 assertTrue(inFile.exists()); 221 assertTrue(outFile.exists()); 222 223 //Check to see if the two files are identical 224 boolean result = FileUtils.contentEquals(referenceFile, outFile); 225 226 assertTrue(result); 227 228 } 229 catch (IOException ex) 230 { 231 fail("There was an IO exception. Check file names and locations."); 232 } 233 } 234 235 /** 236 * Test of toXML method, of class ScriptIncident. 237 */ 238 public void testToXML() 239 { 240 try 241 { 242 System.out.println("toXML"); 243 File inFile = new File("test/scriptbuilder/structures/test_input_file.xml"); 244 assertTrue(inFile.exists()); 245 File referenceFile = new File("test/scriptbuilder/structures/single_incident_output_expected.xml"); 246 assertTrue(referenceFile.exists()); 247 ScriptIncident instance = null; 248 SimulationScript script = new SimulationScript(); 249 script.loadScriptFromFile(inFile); 250 for (ScriptIncident inc : script.incidents) 251 { 252 if (inc != null && inc.number == 187) 253 { 254 instance = inc; 255 } 256 } 257 258 String expResult; 259 260 byte[] data = Files.readAllBytes(referenceFile.toPath()); 261 262 expResult = new String(data); 263 264 String result = instance.toXML(); 265 assertEquals(expResult, result); 266 267 } 268 catch (Exception ex) 269 { 270 fail("There was an IO exception. Check file names and locations."); 271 } 272 } 273 274 /** 275 * Test of insertCadData method, of class ScriptIncident. 276 */ 277 public void testInsertCadData() 278 { 279 System.out.println("insertCadData"); 280 CadData cad = new CadData(); 281 mockedScript = mock(SimulationScript.class); 282 ScriptIncident instance = new ScriptIncident(100, "test", "test", mockedScript); 283 284 assertEquals(0, instance.slices.size()); 285 instance.insertCadData(10, cad); 286 assertEquals(1, instance.slices.size()); 287 } 178 288 }
Note: See TracChangeset
for help on using the changeset viewer.
