01.02.2013 Views

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

putting code to the test<br />

260 Chapter 7<br />

Below is some code from the BeatBox Pro application. Your job is<br />

to come up with tests to get 100% coverage on this code... or as<br />

close to it as you can get.<br />

public class RemoteReader implements Runnable {<br />

boolean[] checkboxState = null;<br />

String nameToShow = null;<br />

Object obj = null;<br />

public void run() {<br />

try {<br />

while ((obj = in.readObject()) != null) {<br />

System.out.println(“got an object from server”);<br />

System.out.println(obj.getClass());<br />

String nameToShow = (String) obj;<br />

checkboxState = (boolean[]) in.readObject();<br />

if (nameToShow.equals(PICTURE_START_SEQUENCE)) {<br />

receiveJPEG();<br />

} else {<br />

if (nameToShow.equals(POKE_START_SEQUENCE)) {<br />

playPoke();<br />

nameToShow = “Hey! Pay attention.”;<br />

}<br />

otherSeqsMap.put(nameToShow, checkboxState);<br />

listVector.add(nameToShow);<br />

incomingList.setListData(listVector);<br />

// now reset the sequence to be this<br />

}<br />

} // close while<br />

} catch (Exception ex) {<br />

ex.printStackTrace();<br />

}<br />

} // close run<br />

} // close inner class<br />

Download at WoweBook.Com<br />

This is the code that<br />

handles the picture and<br />

poke sequences, as well<br />

as normal messages.<br />

Circle any code that<br />

your tests don’t cover.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!