WEBVTT 1 00:00:00.222 --> 00:00:02.119 The room class now has some significant 2 00:00:02.220 --> 00:00:06.001 additional capability to allow rooms to be linked together. 3 00:00:06.220 --> 00:00:08.112 In this demo I'm going to test this 4 00:00:08.113 --> 00:00:10.113 new version of the room class 5 00:00:11.224 --> 00:00:13.223 to do this I need to add a new test 6 00:00:13.224 --> 00:00:16.002 to the unit test class RoomTest 7 00:00:16.113 --> 00:00:18.003 so let's open that class. 8 00:00:19.111 --> 00:00:21.223 My test is going to need some additional test objects 9 00:00:21.224 --> 00:00:25.003 I need some extra rooms, so lets declare 10 00:00:26.224 --> 00:00:29.228 some new rooms, room two 11 00:00:34.224 --> 00:00:39.112 room three and 12 00:00:42.222 --> 00:00:45.119 room four, that should be enough. 13 00:00:47.220 --> 00:00:51.003 Next I'll need to create these new room objects 14 00:00:51.004 --> 00:00:54.110 in the setup method, so lets 15 00:00:54.221 --> 00:00:57.113 add some code here, I'm just going to paste 16 00:00:57.114 --> 00:00:59.119 this code for speed 17 00:01:01.112 --> 00:01:05.225 so there we go, three new room objects 18 00:01:07.225 --> 00:01:09.229 just note there at room three 19 00:01:10.003 --> 00:01:11.114 has the description hall 20 00:01:11.115 --> 00:01:13.004 because that's going to be important. 21 00:01:14.007 --> 00:01:16.008 Now I need to link some rooms together 22 00:01:16.220 --> 00:01:18.228 so I'm going to add some code to 23 00:01:19.003 --> 00:01:21.225 setup these three new rooms 24 00:01:22.001 --> 00:01:25.113 as the exits of the first room 25 00:01:26.002 --> 00:01:29.004 so here's the code to do that. 26 00:01:29.229 --> 00:01:32.113 So note there that room three 27 00:01:32.225 --> 00:01:37.223 has been setup as the exit for room one labelled north 28 00:01:39.006 --> 00:01:41.118 note that these new test objects will not have any 29 00:01:41.119 --> 00:01:44.009 effect on the existing test method which relates only 30 00:01:44.110 --> 00:01:46.115 to the items in the first room. 31 00:01:47.226 --> 00:01:50.118 Now that I've got the new test objects included 32 00:01:50.222 --> 00:01:53.119 I just need to add a new test method 33 00:01:53.220 --> 00:01:56.117 which I'm going to do here 34 00:01:57.005 --> 00:01:59.112 after the previous test method. 35 00:02:01.224 --> 00:02:04.006 This tests that the GetExit method of room 36 00:02:04.007 --> 00:02:07.113 is working correctly and that for a given label 37 00:02:07.117 --> 00:02:10.000 it will return the correct room, so the test 38 00:02:10.001 --> 00:02:12.220 method is called testGetExit 39 00:02:13.003 --> 00:02:16.001 recall that in setting up the test objects I assigned the 40 00:02:16.002 --> 00:02:20.223 the label north to a room with the description hall. 41 00:02:21.116 --> 00:02:25.005 So the test method calls the getExit method of room one 42 00:02:25.114 --> 00:02:28.118 supplies the label north as a parameter and assigns 43 00:02:28.119 --> 00:02:31.226 the resulting room object to a variable target 44 00:02:32.112 --> 00:02:34.224 it then asserts that the description 45 00:02:35.000 --> 00:02:38.110 field of that target object is in fact hall 46 00:02:38.118 --> 00:02:43.004 and if thats true the test passes, if its not the test fails. 47 00:02:45.006 --> 00:02:47.116 So lets compile the test class 48 00:02:47.227 --> 00:02:51.115 which compiles with no errors and now if I run 49 00:02:51.223 --> 00:02:55.225 the tests in the Room class, either by using Test All 50 00:02:56.111 --> 00:02:58.229 or by clicking the run test button 51 00:02:59.222 --> 00:03:02.112 you see that two tests have run, testGetItem 52 00:03:02.116 --> 00:03:05.119 and testGetExit, they both pass 53 00:03:05.222 --> 00:03:07.229 so I get a green bar showing me that 54 00:03:08.000 --> 00:03:11.115 all the tests in the project are passing successfully. 55 00:03:14.220 --> 00:03:17.005 Note that when you add new functionality to a class 56 00:03:17.006 --> 00:03:19.007 and new tests for that functionality 57 00:03:19.117 --> 00:03:22.118 you should also rerun the existing test in the project 58 00:03:22.225 --> 00:03:24.005 and thats what we've done here.