aspose file tools*
The moose likes Testing and the fly likes What causes these two errors? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "What causes these two errors?" Watch "What causes these two errors?" New topic
Author

What causes these two errors?

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
The following clases display two errors when tested with junit3.8.1
in the methods testCreate, testCourseSessionDates, testCourseDates




<CLASS>
<CourseSession.java class>
package studentinfo;




import java.util.*;

//import java.util.Date;
//import java.util.Calendar;
//import java.util.GregorianCalendar;

/* If import is not used , then the fully qualified name of the class
* has to be used. eg:-java.util.ArrayList*/


class CourseSession{

private String department;
private String number;
private ArrayList<Student> students = new ArrayList<Student>();
private Date startDate;


//Constructors
CourseSession(String department, String number){
this.department=department;
this.number=number;
}
CourseSession(String department, String number, Date startdate){

this.department = department;
this.number = number;
this.startDate = startDate;

}



//Methods
String getDepartment(){
return department;
}
String getNumber(){
return number;

}
int getNumberOfStudents(){
return students.size();

}
void enroll(Student student){
students.add(student);

}
Student get(int index){
return students.get(index);
}
Date getStartDate(){
return startDate;
}
Date getEndDate(){
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
int numberOfDays = 16 * 7 - 3;
calendar.add(Calendar.DAY_OF_YEAR, numberOfDays);
return calendar.getTime();

}

}

</CourseSession.java>
</CLASS>


<CLASS>
<CourseSessionTest>
package studentinfo;

import junit.framework.TestCase;
import java.util.*;
//import java.util.Date;
/* If import is not used , then the fully qualified name of the class
* has to be used. eg:-java.util.ArrayList*/


public class CourseSessionTest extends TestCase{

private CourseSession session;
private Student student;
private Date startDate;


public void setUp(){//SetUp() is case sensitive


int year = 103;
int month = 0;
int date = 6;
startDate = createDate(year, month, date);
session =new CourseSession("ENGL", "101", startDate);

}


public void testCreate(){
//CourseSession session=new CourseSession("ENGL", "101");
assertEquals("ENGL", session.getDepartment());
assertEquals("101", session.getNumber());
assertEquals(0,session.getNumberOfStudents());
assertEquals(startDate, session.getStartDate());


}
public void testEnrollStudents(){


Student student1=new Student("Cain DiVoe");
session.enroll(student1);
assertEquals(1, session.getNumberOfStudents());
//ArrayList<Student> allStudents = session.getAllStudents();
//assertEquals(1, session.size());
assertEquals(student1, session.get(0));



Student student2=new Student("Coralee DeVaughn");
session.enroll(student2);
assertEquals(2, session.getNumberOfStudents());
//assertEquals(2, student);
assertEquals(student1, session.get(0));
assertEquals(student2, session.get(1));


}
public void testCourseSessionDates(){
int year = 103;
int month = 0;
int date = 6;

Date startDate=new Date(year, month, date);

CourseSession session= new CourseSession("ABCD", "200", startDate);

year = 103;
month = 3;
date = 25;

Date sixteenWeeksOut = new Date(year, month, date);
assertEquals(sixteenWeeksOut, session.getEndDate());


}public void testCourseDates(){


int year = 103;
int month = 3;
int date = 25;
Date sixteenWeeksOut = new Date(year, month, date);
assertEquals(sixteenWeeksOut, session.getEndDate());

}
Date createDate(int year, int month, int date){

GregorianCalendar calendar = new GregorianCalendar();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month-1);
calendar.set(Calendar.DAY_OF_MONTH, date);

return calendar.getTime();


}

}

</CourseSessionTest>
</CLASS>


Varuna Seneviratna
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
I found the error the constructor of CourseSession was using the "startDate" parameter as "startdate" when it should have been "startDate"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What causes these two errors?
 
Similar Threads
Date (GregorianCalender)
Problem with calculating difference of 2 date in days
how to call Remote Interface from a Stand Alone Client in EJB 3.0
While Loop in Gantt Chart values
Sorting Keys(Value Objects) in HashMap