Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

plz write the junit code for all 3 questions and the code is given below for reference -- 1) Rename testDoSomething to testDoSomething1. Write unit

plz write the junit code for all 3 questions and the code is given below for reference --

1) Rename testDoSomething to testDoSomething1. Write unit test that creates a Stringy object initialized with a string that contains an 'r', and then calls doSomething, passing a non-empty string that contains at least one 'r' in the first parameter, and the character 'r' in the second parameter. Add code that tests the string returned from doSomething, as well as the String returned by stringy.getMyString();

2) Write one more test, called testSomething2, which creates a Stringt object with the same string as in testDoSomething1, and then calls doSomething with an empty string passed in as the first parameter. Again, add code that tests the returned value and the contents of the instance variable.

3) Write third test, called testSomething3, which creates a Stringy object initialized with an empty string, and a call to doSomething with a non-empty string and the character 'r'. As before, test the values returned by doSomething and by getMyString.

raw code --

Stringy.java ------

/**

* Maintains a string and provides routine for

* manipulating that string

* @author BKM

*

*/

public class Stringy {

private String myString;

public Stringy(String str){

myString = str;

}

/**

* returns the string maintained by the Stringy class

*/

public String getMyString() {

return myString;

}

/**

* Concatenates the string parameter to the front of

* the string stored in Stringy. It returns a new string

* in which all occurrences of the character

* passed in the parameter ch are replaced with the letter 'X'

*/

public String doSomething(String anotherStr, char ch) {

myString = anotherStr + myString;

String newString = myString.replace(ch, 'X');

return newString;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Applied Regression Analysis And Other Multivariable Methods

Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg

5th Edition

1285051084, 978-1285963754, 128596375X, 978-1285051086

More Books

Students also viewed these Programming questions