Can someone help writing JUnit for these methods Override S
Can someone help writing JUnit for these methods:
@Override
// Songs ordered by artist in ascending order.
public int compareTo(Song s){
int a = this.artist.compareTo(s.artist);
if(a < 0){
return -1;
}
else if(a > 0){
return 1;
}
else
if(a == 0){
int a2 = this.title.compareTo(s.title);
if(a2 < 0){
return -1;
}
else
if(a2 > 0){
return 1;
}
else
if(a2 == 0){
int a3 = this.title.compareTo(s.title);
if(a3 < 0){
return -1;
}
else
if(a3 > 0){
return 1;
}
}
}
return 0;
}
@Override
// gets how much seconds a song last
public int getPlayTimeSeconds()
{
int sum = 0;
sum = this.minutes*60;
sum = sum + this.seconds;
return sum;
}
//returns the number of songs in the play list and all songs contained in any of the nested play lists
public int size(){
int total = playableList.size();
int i=0;
for(Playable p: playableList){
if(p instanceof PlayList){
PlayList p1 = (PlayList)p;
total = total + p1.size();
}
Solution
test cases...
public void testSize() {
System.out.println(\"testSize\");
ArrayList<playableList> list = new ArrayList<playableList>();
int expResult = 0;
int result = list.size();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail(\"The size test case fails....\");
}
public void testPlayTimeSeconds() {
System.out.println(\"testPlayTimeSeconds\");
this.minutes = 2;
this.seconds = 10;
int expResult = 130;
int result = getPlayTimeSeconds();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail(\"The testPlayTimeSeconds test case fails....\");
}
public void testCompare() {
System.out.println(\"testCompare\");
int expResult = 0;
int result = this.compareTo(this);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail(\"The testCompare test case fails....\");
}


