Question

I'm trying to test a null return in some code: public Time getStartTime()    { if...

I'm trying to test a null return in some code:

public Time getStartTime()   
{
if (this.startTime == null)   
{
return null;
}   
return new Time(this.startTime);

When I test it, I'm trying to use:

Runner runnerTest3 = new Runner();
RunnerResult runnerResultTest3 = new RunnerResult("RD1234", runnerTest3);
  
Time timeTest3 = new Time();
runnerResultTest3.setEndTime(timeTest3);
  
assertNull(timeTest3);
  
assertNull(null, runnerResultTest3.getEndTime().getHrs());
assertNull(null, runnerResultTest3.getEndTime().getMins());
assertNull(null, runnerResultTest3.getEndTime().getSecs());

It will not compile and will throw errors. I'm not sure what I'm missing

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

Your error is in these statements.

assertNull(null, runnerResultTest3.getEndTime().getHrs());
assertNull(null, runnerResultTest3.getEndTime().getMins());
assertNull(null, runnerResultTest3.getEndTime().getSecs());

assertNull takes only one parameter, determines if it is null or not, but you have provided two. I think you tried to use the syntax of assertEquals. So there are two options to correct this.

1) Use this

assertNull(runnerResultTest3.getEndTime().getHrs());
assertNull (runnerResultTest3.getEndTime().getMins());
assertNull (runnerResultTest3.getEndTime().getSecs());

or

2) Use this instead of assertNull

assertEquals(runnerResultTest3.getEndTime().getHrs(),null);
assertEquals(runnerResultTest3.getEndTime().getMins(),null);
assertEquals(runnerResultTest3.getEndTime().getSecs(),null);

Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Add a comment
Know the answer?
Add Answer to:
I'm trying to test a null return in some code: public Time getStartTime()    { if...
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
  • I'm trying to recreate an experiment from class but I'm missing some code. I need an...

    I'm trying to recreate an experiment from class but I'm missing some code. I need an arduino uno program that will ask the user to enter a duty cycle and frequency, and to then generate a square pulse width (0-5V) based on those values.

  • 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...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • I'm trying to find out what is wrong with my code? package DriverClass; public class DriveClass...

    I'm trying to find out what is wrong with my code? package DriverClass; public class DriveClass { public static void main(String[] args) { int a[] = {3, 2, 5, 6, 1}; InsertionSortClass insertion = new InsertionSortClass(); System.out.print("The original list : "); System.out.println(); insertion.printArray(a); System.out.println(); System.out.println("The list after insertionSort : "); System.out.println(); insertion.insertionSort(a); } } package DriverClass; public interface SortADTInterface { public void insertionSort(int arr[]); public void printArray(int arr[]); } package DriverClass; public class InsertionSortClass implements SortADTInterface{ public void insertionSort(int[] arr)...

  • I am not passing some of the code when i run the testing . PriorityQueue public...

    I am not passing some of the code when i run the testing . PriorityQueue public class PriorityQueue<T extends Comparable<T>> implements IPriorityQueue<T> {    private Vector<T> theVector = new Vector<>(0, 1);    private int size = 0;    @Override    public void insert(T element) {        theVector.pushBack(element);        size++;        bubbleUp(); }    @Override    public T peekTop() throws java.util.NoSuchElementException {        if (isEmpty()) {            throw new java.util.NoSuchElementException();        }       ...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • Please help me to answer the 5 programming questions and give some specific explanations, thanks a...

    Please help me to answer the 5 programming questions and give some specific explanations, thanks a lot !!! Question Consider a class hierarchy that includes a class called Creature, with subclasses called Unicorn and Dragon. The Creature class has a method called feelsLike, Not yet answered which is overridden in the Unicorn and Dragon class. Marked out of The feelsLike method of the Creature class returns "smooth", while the feelsLike method is overridden in the Unicorn class to return "fluffy"...

  • Trying to write this in java code but I'm running into a lot of errors. package...

    Trying to write this in java code but I'm running into a lot of errors. package receipt; public class Receipt {    {          int quantity=2, tax=7,i;    String item="0010", description="Paper";    double amt=1.99, amount=4.26, total=12.78,    ("\t\t\t\t", "Receipt");    ("Item#\t", "Description\t", "Amt\t", "Quantity\t", "Tax\t", "Amount\t");    for(i=1;i<=3;i++)    {    cout<<item<<"\t"<<description<<"\t\t"<<amt<<"\t"<<quantity<<"\t\t"<<tax<<"%\t"<<amount<<endl;    }    cout<<"\n\t\t\t\t\t\tTotal\t"<<total<<endl;    return;    }} The end result would look like this. Receipt Item# Description Amt Quantity Tax Amount 0010 Paper 0010 Paper...

  • I need some help on Java. I'm stuck on trying to generate a new string by...

    I need some help on Java. I'm stuck on trying to generate a new string by concatenating the reversed substrings of even indexes and odd indexes separately from a given string. I'm not sure how to figure this out. See example. Example: Input: abscacd Output: dasaccb Substrings: asad, bcc Reversed substrings: dasa, ccb.

  • Hi I'm trying to write a code for a web server in python with flask. This...

    Hi I'm trying to write a code for a web server in python with flask. This is what I have so far from flask import Flask app = Flask(__name__) @app.route('/') #first endpoint i.e. "http://localhost/" def index(): return 'hello' #return data in string if __name__ == '__main__': app.run(debug=True) After running the code, I'm given a address to the web with the text hello. The problem is that this only works with my computer that is running the code. If I try...

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