473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

JUnit testing returns an error

thatos
105 100+
I have the class TableCollection which creates tables for data store in the given direcoty, the method which reads this goes like this.
Expand|Select|Wrap|Line Numbers
  1. public void read(String dirname,String regex) throws IOException{
  2.  
where dirname is the directory name and regex is a regular expression which allows the read method to only take files in that directory which matches that expression.
On my JUnit testing I have the following test:
The test tests whether the path or directory is valid or not
Expand|Select|Wrap|Line Numbers
  1.   @Test  //2 
  2.  
  3.   public void testPathInvalid() throws IOException {
  4.     TableCollection all = new TableCollection();
  5.     try {
  6.       all.read("junk/file","");
  7.     } 
  8.     catch
  9.       (FileNotFoundException e) {
  10.       return;
  11.     }
  12.     fail("FileNotFoundException expected");
  13.  
  14.   }
  15.  
  16. //This returns the following error
  17.  java.lang.NullPointerException from line:61 i.e all.read("junk/file","");
  18.  
On my read method must I include statements which firsts check whether the path in valid or not and throws an exception?
Jul 9 '08 #1
1 1212
thatos
105 100+
I found the solution to this, I placed the following statements on the read method
Expand|Select|Wrap|Line Numbers
  1.     File directory = new File(dirname);
  2.     boolean exists = directory.exists();
  3.     if(!exists){
  4.       throw new FileNotFoundException();
  5.     }
  6.  
Jul 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Captain | last post by:
How do you junit test a container managed security (2.3. Servlet) environment within Tomcat 4.1.x using JUnit?? I.e. form based authentication. I had expected the following to work... but alas...
0
by: Linus Nikander | last post by:
Browsing peoples comments at amazon might be rewarding, but it sure takes a lot of time. I'm trying to find good (best) books for a couple of java-related areas. As most people who subscribe to...
0
by: Cedric Beust | last post by:
I just published the first version of a testing framework based on ideas from JUnit and NUnit. The announcement can be found at: http://beust.com/weblog/archives/000121.html and an ongoing...
4
by: Beatrice Rutger | last post by:
Is there aan equivalent of JUnit for unit testing (Visual) C++ code ? tkx, B.
3
by: knightsmastergeneral | last post by:
Hi, I'm currently working on getting junit and junireport to take some java files, convert it to xml and then display error messages / success rates etc in html which is one of the features of...
0
by: sandhu236 | last post by:
Hi all, Can someone help me in testing the loops in junit,and how to test datapools in testing? I just want to know how an i assert the values when n number of variables are assigned in the...
1
by: kokababu | last post by:
HI, I am new in Junit testing. I don't know how to test EJB with Junit. I have found people using mock object to test EJB, I am not clear about it. Can anyone give me some advice from where I...
1
by: kokababu | last post by:
HI, I am little bit confuse how to test EJB with JUnit, using DynaMock object Can anyone give me some advice from where I should begin? and any good tutorial for EJB testing, using JUnit? ...
4
by: eazyigz | last post by:
I downloaded Junit 4.5 and am using the TestRunner class to test the AllTests class in the junit/tests package. I am issuing the following command at a DOS prompt: java -classpath junit-4.5.jar;....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.