Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

unit testing - Test value(s) for an invalid Linux path-name for Java code

I'm unit testing some Java code that must parse an input String as a path-name. I'm using Java 7, so the parsed value is a Path object.

The Paths.get method will throw an InvalidPathException

if the path string cannot be converted to a Path

So, to check my parsing code is robust I need a test value that will cause Paths.get to throw that exception. That is, a String value that is not a valid path. What constitutes a valid path is system (even file-system) dependent, so I am specifically interested in a String that is not a valid POSIX path, or (failing that) not a valid Linux path.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

POSIX path-names may not contain null characters. Therefore a String that consists of a single NUL character (Unicode code-point 0) will be invalid. That is, the String "". I can confirm that Open JDK throws a InvalidPathException, with the message Nul character not allowed, for this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...