Hi there I am having trouble trying to JUNIT test my Constructors with invalid args. Everything else in my test works but when I try to execute the test case with the invalid constructors values I am getting following error:
"Expected IllegalArgumentException to be thrown but nothing was thrown".
here is my code.
package song;
public abstract class song {
private String name;
private String genre;
private double length;
private int chartNumber;
/**
* Setting the limit values
*
*/
public final static int NAME_LOWER_LIMIT = 1;
public final static int CHART_LOWER_LIMIT = 1;
public final static int CHART_UPPER_LIMIT = 10;
public final static int GENRE_LENGTH = 1;
public final static double LENGTH_LOWER_LIMIT = 1.00;
public final static double LENGTH_UPPER_LIMIT = 5.00;
public song() {
}
public song(String name, String genre, double length, int chartNumber) {
super();
this.name = name;
this.genre = genre;
this.length = length;
this.chartNumber = chartNumber;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
* Name must have at least one character
*/
public void setName(String name) throws IllegalArgumentException{
if(name.length()>=NAME_LOWER_LIMIT) {
this.name = name;
} else {
throw new IllegalArgumentException("Name value too short");
}
}
/**
* @return the genre
*/
public String getGenre() {
return genre;
}
/**
* @param genre the genre to set
* Genre must be at least one charter
*/
public void setGenre(String genre) throws IllegalArgumentException {
if(genre.length()>=GENRE_LENGTH) {
this.genre = genre;
} else {
throw new IllegalArgumentException("Genre name too short");
}
}
/**
* @return the length
*/
public double getLength() {
return length;
}
/**
* @param length the length to set
* Length has to be greater than 1.00 and less than 5.00
*/
public void setLength(double length) throws IllegalArgumentException {
if((length >= LENGTH_LOWER_LIMIT) && (length <= LENGTH_UPPER_LIMIT)) {
this.length = length;
} else {
throw new IllegalArgumentException("song length not inside the boundries");
}
}
/**
* @return the chartNumber
* Chart limit has to be between 1 -20
*/
public int getChartNumber() {
return chartNumber;
}
/**
* @param chartNumber the chartNumber to set
* Chart number must be between 1 -10
*/
public void setChartNumber(int chartNumber) throws IllegalArgumentException {
if((chartNumber >= CHART_LOWER_LIMIT) && (chartNumber<= CHART_UPPER_LIMIT)) {
this.chartNumber = chartNumber;
} else {
throw new IllegalArgumentException("Chart not in bounds");
}
}
}
Following is the my test case code.
package testartist;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import song.Artist;
class TestArtist {
String name,nameInvalid, genre,genreInvalid, artistName, artistNameInvalid;
int chartNumber, chartNumberInvalid;
double length, lengthInvalid;
@BeforeEach
void setUp() throws Exception {
name = "Beautiful day";
nameInvalid = "";
genre = "Country";
genreInvalid = "";
artistName = "Bono";
artistNameInvalid = "";
chartNumber = 3;
chartNumberInvalid = 15;
length = 2.56;
lengthInvalid = 5.45;
}
@Test
void testDefaultConstructor() {
Artist song = new Artist();
}
@Test
void testConstructorWithArgs() {
Artist artist = new Artist(name, genre, length, chartNumber, artistName);
assertEquals(name, artist.getName() );
assertEquals(genre, artist.getGenre() );
assertEquals(length, artist.getLength() );
assertEquals(chartNumber, artist.getChartNumber());
assertEquals(artistName, artist.getArtistName());
}
@Test
void testInvalidConstructorWithArgs() {
assertThrows(IllegalArgumentException.class, () -> {
Artist artist = new Artist(name, genre, length, chartNumber, artistNameInvalid);
});
}
@Test
void testSetGetArtistName() {
Artist a = new Artist();
a.setArtistName(artistName);
assertEquals(artistName, a.getArtistName());
}
@Test
void testSetGetName() {
Artist a = new Artist();
a.setName(name);
assertEquals(name, a.getName());
}
@Test
void testSetGetGenre() {
Artist a = new Artist();
a.setGenre(genre);
assertEquals(genre, a.getGenre());
}
@Test
void testSetGetLength() {
Artist a = new Artist();
a.setLength(length);
assertEquals(length, a.getLength());
}
@Test
void testSetGetChartNumber() {
Artist a = new Artist();
a.setChartNumber(chartNumber);
assertEquals(chartNumber, a.getChartNumber());
}
}
** Artist code
package song;
public class Artist extends song {
private static final int ARTIST_NAME_LOWER_LIMIT = 1;
private String artistName;
public Artist() {
}
public Artist(String name, String genre, double length, int chartNumber, String artistName) {
super(name, genre, length, chartNumber);
this.artistName = artistName;
}
/**
* @return the artistName
*/
public String getArtistName() {
return artistName;
}
/**
* @param artistName the artistName to set
*/
public void setArtistName(String artistName) throws IllegalArgumentException{
if( artistName.length()>= ARTIST_NAME_LOWER_LIMIT) {
this.artistName = artistName;
} else {
throw new IllegalArgumentException("Name too short");
}
}
order accutane online canada – accutane price online pharmacy buy accutane online without prescription
buy amoxicilin – amoxicillin for sale for humans buy amoxicilin 500 mg canada
levitra 10mg – vardenafil 20 mg online generic vardenafil mexico
ivermectin oral 0 8 – ivermectin 200 ivermectin 0.1
buy lyrica 300mg – online pharmacy school legit canadian online pharmacy
stromectol generic – ivermectin canada ivermectin us
how much is prednisone 5mg – prednisone without a script prednisone price canada
buy azithromycin 100mg online – zithromax pills online generic zithromax 100mg
buy furosemide uk – furosemide 40 mg price lasix for sale
clomid 100mg – order clomiphene clomid pct
viagra usa price – order sildenafil online uk cheap viagra pills for sale
cialis 40 mg – tadalafil 22 mg generic cialis lowest prices
casino world – online slots casino slots
canadian pharmacy 5 mg prednisone no rx – prednisone 5mg capsules over the counter prednisone pills
sildenafil canada where to buy – cheap generic viagra online canada discount viagra prices
57290 101502We maintain your page. Watch it offline again soon. Extremely fascinating write-up. 668616
174826 447307I just added this webpage to my feed reader, excellent stuff. Cannot get enough! 782537
316523 614354Great post, I think site owners ought to acquire a great deal from this internet website its extremely user pleasant. 192782
female viagra sildenafil – buy generic viagra 50mg cialis 10mg cheap
tadalafil order online no prescription tadalafil without a doctor prescription
tadalafil dosage generic cialis online fast shipping
tadalafil blood pressure cialis tadalafil
cost tadalafil generic where to order tadalafil tablets
955905 377056Perfect just what I was searching for! . 33565
tadalafil cost walmart where to get tadalafil
generic tadalafil from uk buy cialis
https://cialisedot.com/ tadalafil generic
cheap cialis pills for sale tadalafil cost in canada
tadalafil cost walmart tadalafil drug
tadalafil brands where to buy tadalafil on line
tadalafil liquid tadalafil blood pressure
226592 43844When do you feel this Real Estate market will go back in a positive direction? Or is it nonetheless too early to tell? We are seeing plenty of housing foreclosures in Altamonte Springs Florida. What about you? Would really like to get your feedback on this. 486131
buy 12 mg stromectol stromectol 30mg
https://ivermectinuni.com/ buy generic stromectol online
stromectol 12 mg
how to get ivermectin from india
order ivermectin from india stromectol