Assignment3Part1Comments

Assignment3Part1Comments - CS 580 Client-Server Programming...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 580 Client-Server Programming Spring Semester, 2010 Doc 10 Comments on Assignment 3 part 1 2 March, 2010 Testing Exceptions 2 @Test public void testChatLogin4() { System.out.println("chatLogin"); String nicknameIN = "foobar"; String passwordIN = "sdchat"; boolean expResult = true; boolean exceptionOccurred = false; SDChatCommon instance = new SDChatCommon(); try { instance.chatLogin(nicknameIN, passwordIN); } catch (Exception e) { exceptionOccurred = true; } assertEquals(expResult, exceptionOccurred); } Testing Exceptions 2 @Test public void testChatLogin4() { System.out.println("chatLogin"); String nicknameIN = "foobar"; String passwordIN = "sdchat"; boolean expResult = true; boolean exceptionOccurred = false; SDChatCommon instance = new SDChatCommon(); try { instance.chatLogin(nicknameIN, passwordIN); } catch (Exception e) { exceptionOccurred = true; } assertEquals(expResult, exceptionOccurred); } Shorter Version 3 @Test(expected = Exception.class) public void testChatLogin4() throws Exception { String nicknameIN = "foobar"; String passwordIN = "sdchat"; SDChatCommon instance = new SDChatCommon(); instance.chatLogin(nicknameIN, passwordIN); } Name 4 @Test(expected = Exception.class) public void testChatLoginNonValidUser() throws Exception { String nicknameIN = "foobar"; String passwordIN = "sdchat"; SDChatCommon instance = new SDChatCommon(); instance.chatLogin(nicknameIN, passwordIN); } Client or server Test 5 @Test(expected = Exception.class) public void testChatLoginEmptyPassword() throws Exception { String nicknameIN = "foobar"; String passwordIN = ""; SDChatCommon instance = new SDChatCommon(); instance.chatLogin(nicknameIN, passwordIN); } GUI & Domain Logic 6 public void chatLogin(String nicknameIN, String passwordIN) throws Exception { if ( currentState == 0 ) { StringBuffer loginLine = new StringBuffer("login"); if ( nicknameIN == null || nicknameIN.trim().length() == 0 ) throw new Exception("Error: Nickname cannot be blank!"); if ( passwordIN == null || passwordIN.trim().length() == 0 ) throw new Exception("Error: Password cannot be blank!"); loginLine.append(";nickname:"+escapeString(nicknameIN)); loginLine.append(";password:"+escapeString(passwordIN)); loginLine.append(";;"); String response = sendAndReceive(loginLine.toString()); if ( response.startsWith("error:") ) throw new Exception(parseError(response)); else currentState++; } } Modified 7 public boolean chatLogin(String nicknameIN, String passwordIN) { if ( currentState == START ) { StringBuffer loginLine = new StringBuffer("login"); loginLine.append(";nickname:"+escapeString(nicknameIN)); loginLine.append(";password:"+escapeString(passwordIN)); loginLine.append(";;"); String response = sendAndReceive(loginLine.toString()); if ( response.startsWith("error:") ) return false; currentState = AUTHENTICATED; return true } } Menu Systems 8 SDChatCommon testChat = new SDChatCommon(); String textEntered = ""; // Line read from standard in System.out.println("You are in the "+testChat.getState()+" state. System....
View Full Document

Page1 / 29

Assignment3Part1Comments - CS 580 Client-Server Programming...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online