Skip to content

Instantly share code, notes, and snippets.

@joannakl
Last active October 6, 2019 19:02
Show Gist options
  • Save joannakl/21a56941b9911cc1954442fb92a338a4 to your computer and use it in GitHub Desktop.
Save joannakl/21a56941b9911cc1954442fb92a338a4 to your computer and use it in GitHub Desktop.
public class Movie implements Comparable<Movie> {
private String title;
private int year;
private ArrayList<Location> locations;
private String director;
private String writer;
private ArrayList<Actor> actors;
public Movie(String title, int year) {
}
public Movie(String title, int year, String director, String writer,
Actor actor1, Actor actor2, Actor actor3) {
}
public void addLocation(Location loc) {
}
@Override
public boolean equals(Object obj) {
return false;
}
@Override
public String toString() {
return null;
}
@Override
public int compareTo(Movie other) {
return 0;
}
}
/**
* Tests if the constructor can handle invalid parameters: title
*/
@Test
public void testMovieConstructorNegativeEmptyTitle() {
try {
Movie n = new Movie("", 1990); // provide invalid params
fail("testMovieConstructorNegativeEmptyTitle failed: The program continued without throwing an exception "
+ "for invalid constructor arguments");
} catch (IllegalArgumentException e) {
//this is what we want
assertTrue(true);
} catch (Exception e) {
fail("testMovieConstructorNegativeEmptyTitle failed: Incorrect exception thrown\n" );
}
}
/**
* Tests if the constructor can handle invalid parameters: title
*/
@Test
public void testMovieConstructorNegativeNullTitle() {
try {
Movie n = new Movie(null, 1990); // provide invalid params
fail("testMovieConstructorNegativeNullTitle failed: The program continued without throwing an exception "
+ "for invalid constructor arguments");
} catch (IllegalArgumentException e) {
//this is what we want
assertTrue(true);
} catch (Exception e) {
fail("testMovieConstructorNegativeNullTitle failed: Incorrect exception thrown\n" );
}
}
/**
* Tests if the constructor can handle invalid parameters: year not in range
*/
@Test
public void testMovieConstructorNegativeYear() {
try {
Movie n = new Movie("Test", 1890); // provide invalid params
fail("testMovieConstructorNegativeYear failed: The program continued without throwing an exception "
+ "for invalid constructor arguments");
} catch (IllegalArgumentException e) {
//this is what we want
assertTrue(true);
} catch (Exception e) {
fail("testMovieConstructorNegativeYear failed: Incorrect exception thrown\n" );
}
try {
Movie n = new Movie("Test", 2100); // provide invalid params
fail("testMovieConstructorNegativeYear failed: The program continued without throwing an exception "
+ "for invalid constructor arguments");
} catch (IllegalArgumentException e) {
//this is what we want
assertTrue(true);
} catch (Exception e) {
fail("testMovieConstructorNegativeYear failed: Incorrect exception thrown\n" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment