Having trouble understanding what this test case code is doing

Tim

I am in CS1050, and we are doing a lab that includes grabbing information from files in order to print new information onto a different file. I have no idea what one of the methods my teacher wrote in the test case class is trying to do. Ive looked up all of the methods that this method uses, but I dont know what the end result is.

static String getBadPath(String name) {
        return new File(new File(TestSuite.class.getResource("empty.txt").getPath()).getParent(), name).getAbsolutePath();
    }
haoyu wang

This basically get the absolute path of a file whose name is name and resides in the same directory with empty.txt.

You can break it down into following code:

//get the File object named "empty.txt".
File emptyTxt=new File(TestSuite.class.getResource("empty.txt").getPath());
//get the directory this emptyTxt reside in
File parentDirectory=emptyTxt.getPath().getParent();
//get the File whose name is same as the parameter name and reside in parentDirectory.
File resultFile=new File(parentDirectory,name)
//return the absolute path of the resultFile 
return resultFile.getAbsolutePath();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Failed test case, what am I doing wrong?

Having some trouble understanding middleware

Buffer to integer. Having trouble understanding this line of code

Need help in understanding the Erlang code and what exactly it is doing

Haskell - Having trouble understanding a small bit of code

Having trouble understanding currying

Group by and having trouble understanding

Having trouble fetching from an api not sure what I am doing wrong?

Having trouble figuring out what this code does

Having some trouble with case statement

Having trouble understanding the map() method

I'm having trouble understanding the syntax used in a piece of code

Having trouble understanding call signatures

Having trouble getting results from this query. What am I doing wrong?

Having trouble understanding sequence diagrams

I am having trouble understanding part of an ExceptionError code

Having trouble understanding a portion of code (bit operation)

Having trouble understanding a portion of code

Having trouble understanding ajax calls

Having trouble displaying code

Having trouble understanding pointer operations

Having trouble understanding .this keyword use in this code

Having trouble with mysql variables, what am I doing wrong here?

Having trouble understanding the upper bound and lower bound in the following R code

Difference hashing and understanding what these lines of code are doing?

Having trouble understanding part of my code, The Fisher–Yates shuffle

Having trouble understanding lbu instruction

Async and await - having trouble understanding

Having trouble understanding this assembly code