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?
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
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()...
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! Need help in java!!!!!! I'm trying to put int x[]= {3, 6, 4, 1 } into an ArrayList,sort in ascending order and return it. public ArrayList<Integer> lookOut( int x[]) { ArrayList<Integer> list = new ArrayList<Integer>(); for(int i =0; i < x.length; i++){ list.add(x[i]); Collections.sort(list); } return list; } My test case: public void lookOut() { int x[] = {...
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...
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...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
I am trying to run a couple of functions in my main and It won't output anything if there is anything that you see wrong please help me out. I have to use simple, sometimes slower ways because we can use what we haven't learned yet. Here is my code. package a3; import java.util.Scanner; public class LoopsAndImages { public static void main(String[] args){ String test = "A rabbit has a carrot"; Boolean numbers = hasMoreEvenThanOdd("12344"); System.out.println(test); System.out.println(hideLetterA(test)+" This is the...
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;...
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...
I'm trying to implement a rest() method for my GameCharacter where if a random number between 0-2 is generated then one or the other character rests and gains back about 5 to 10 health points. I don't know if I'm on the right track. Here's my code so far and the rest() method is located at the bottom: import java.util.Objects; import java.util.Random; /** * this class represents a class for role playing game. */ public class GameCharacter { private String...