Question

Need help in Java network,    I'm trying to pass Junit 4 tests.       my...

Need help in Java network,    I'm trying to pass Junit 4 tests.
  
  
my Code:
public Character findIt( String url){


       try {
  
           new URL("myurl").toURI();
           System.out.println("pass");

           }
return null;
   }
Test case:
   @Test
   public void testForValidOrNot(){
      
       ValidOrNot validOrNot = new ValidOrNot();
              
       assertEquals( new Character('pass'), validOrNot.findIt( "my url" ) );
   Trying to see why my code won't pass?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

findIt() just printing the value to the console, instead of that it should return an Character() object, than assertEquals() checks the equality of both objects than it will return true

So you need to return the Character from the assert. Please change code like below

public Character findIt( String url){


try {
  
new URL("myurl").toURI();
return new Character('p');

}
return null;
}
Test case:
@Test
public void testForValidOrNot(){
  
ValidOrNot validOrNot = new ValidOrNot();
  
assertEquals( new Character('p'), validOrNot.findIt( "my url" ) );

Character class will take char only so I am checking with single character p

Note : If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Need help in Java network,    I'm trying to pass Junit 4 tests.       my...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given this JUnit test, write a SentenceCounter class that makes the tests pass: import static org.junit.Assert.*;...

    Given this JUnit test, write a SentenceCounter class that makes the tests pass: import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; /** * Tests that will make us practice writing loops */ public class TestSentenceCounter { private static final String SENTENCE1 = "This is my sentence."; private static final String SENTENCE2 = "These words make another sentence that is longer"; private SentenceCounter sc1; private SentenceCounter sc2;    /** * Create two instances we can play with */ @Before public void setup()...

  • This is my code for a TicTacToe game. However, I don't know how to write JUnit...

    This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe {    private char currentPlayer;    private char[][] board;    private char winner;       /**    * Default constructor    * Initializes the board to be 3 by 3 and...

  • Junit testing case Here are my methods I want to test. Scanner scan = new Scanner(System.in).useDelimiter("\n");...

    Junit testing case Here are my methods I want to test. Scanner scan = new Scanner(System.in).useDelimiter("\n"); public String prompt_FirstName() { System.out.println("First Name:"); String firstName = scan.next(); return firstName; } Here's what i have so far @Test public void testPrompt_first() { Menu inputOutput= new Menu(); String input = "Jane"; InputStream in = new ByteArrayInputStream(input.getBytes()); System.setIn(in); String s = inputOutput.prompt_FirstName(); assertEquals("Jane", s); }

  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestIterator { private List<Integer> list; // See the Java List Interface documentation to understand what all the List methods do ... @Before public void setUp() throws Exception { list = new ArrayList<Integer>(); // TODO also try with a...

  • I need help with my IM (instant messaging) java program, I created the Server, Client, and...

    I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...

  • In Java, write JUnit tests to verify various question-type objects for the following below: public interface...

    In Java, write JUnit tests to verify various question-type objects for the following below: public interface IAnswer {    public String getAnswer();    } import java.util.Scanner; YesNo class: public class YesNo implements IAnswer{            private String question;            public YesNo(String q){                this.question = q;            }                       //This function returns question text            public String getQuestionText() {                return question;...

  • in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka...

    in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka the one that says :               public class SmartString implements SmartStringADT at the beginning //for SmartStringTest.java: import static org.junit.Assert.*; import org.junit.Test; public class SmartStringTest {    //Test insert method    @Test    public void testinsert1() {        SmartString evaluator = new SmartString();        evaluator.insert(0, "Hello");        evaluator.insert(4, ", how are you?");        assertEquals("Hello, how are you?", evaluator.toString());    }   ...

  • Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAn...

    Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() {    return question; } //This function takes answer from user public void answer(String userAnswer) {    // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit....

    This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit. Be sure to follow all style and documentation requirements for THIS class. See the style and documentation requirements posted on Canvas. You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome testString : String + Palindrome (String) + isPalindrome (): boolean The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT