Lab02 Hints and Tips
Part 1
@Test
public void testConvertSlashes()
{
assertEquals(
"/java/hsqldb/doc/images/sqlDDL.gif",
ConvertSlashes.convertSlashes(
"\\java\\hsqldb\\doc\\images\\sqlDDL.gif"));
}
Part 2
-
The BrowserInfo class should define fields of type String
for BrowserName and ClientOsName
private String browserName;
private String clientOsName;
For the get/set methods, you can first define the
fields and then use Eclipse's Source - Generate Getter/Setter
menu so you don't have to write the get/set methods manually
The constructor method should look like:
public BrowserInfo (String userAgent)
{
}
In the constructor, write an if-else that uses the String
class's indexOf method to find appropriate substrings
and then initialize the BrowserInfo class's fields. For
example:
if(userAgent.contains("Chrome"))
{
browserName = "Chrome";
}
else if....
Your test-case class might have several testing
methods to test various combinations of browsers
and operating systems. Here's an example of one
of the test methods:
@Test
public void testChromeWindows10()
{
BrowserInfo bi = new BrowserInfo(
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
assertEquals("Chrome", bi.getBrowserName());
assertEquals("Windows 10", bi.getClientOsName());
}