So I was given some code and I had to write methods for it, print the size of list, first element and some other stuff, I did all that. for the next part of this project though, i have to write Junit tests for it but i only have getters, setters, and a tostring method so i dont know what im supposed to test. i know how to make junit tests and i have a class set up for it but i just dont know what im supposed to test. I have only ever written tests for methods with actual calculatioms so im not sure how im supposed to write a junit test for getters and setters. here is my class and my main. I cant really add more methods to the class because ive already finished everything i need to do for the specs of the program. here is my class and my main.
public class FishData {
private String species; //species of fish
private int minSize; //min size allowed in inches
private String season; //fishing season
private int limit; //number
private Boolean willEat;
//constructor
FishData(String s1, int m, String s2, int I, Boolean w){
species = s1;
minSize = m;
season = s2;
limit = I;
willEat = w;
}
public String toString(){
return species + "" + minSize + "" + season + "" + limit + "" + willEat;
}
public String getName(){
return this.species;
}
public String getSpecies(){
return this.species;
}
public String getSeason(){
return this.season;
}
public Boolean getWillEat(){
return this.willEat;
}
public void setSpecies(String species) {
this.species = species;
}
public void setSeason(String season) {
this.season = season;
}
public void setWillEat(Boolean willEat) {
this.willEat = willEat;
}
public void setminSize(int minSize) {
this.minSize = minSize;
}
public void setlimit(int limit) {
this.limit = limit;
}
}
MAIN
import java.util.Collections;
import java.util.LinkedList;
import java.util.Iterator;
public class GoneFishin {
public static void main(String[] args) {
//create linked list of fish data called fl
LinkedList<FishData> fl = new LinkedList<FishData>();
//Here are a few data items
fl.add(new FishData("American Eel ", 9, " Summer/Spring ", 25, false));
fl.add(new FishData("Hammerhead Shark ", 0, " All Year ", 36, false));
fl.add(new FishData("Horseshoe Crab ", 7, " All Year except May ", 60, false));
fl.add(new FishData("Haddock ", 18, " All Year ", 0, true));
fl.add(new FishData("Tautog ", 16, " late Spring to end of year ", 3, true));
for (FishData element : fl) {
System.out.println(element.toString());
}
System.out.print("SIZE OF LISTt: ");
System.out.println(fl.size());
System.out.print("SECOND ELEMENT IN LIST: ");
System.out.println(fl.get(1));
System.out.print("LAST ELEMENT IN LIST: ");
System.out.println(fl.getLast());
Iterator<FishData> itr2 = fl.iterator();
System.out.println("PRINTING ALL ELEMENTS USING ITERATOR");
while (itr2.hasNext()) {
System.out.println(itr2.next());
}
Iterator<FishData> itr = fl.iterator();
while (itr.hasNext()) {
FishData b = (FishData) itr.next();
if (b.getWillEat()== false) {
itr.remove();
}
}
System.out.println("FISH THAT ARE GOOD TO EAT");
for (FishData element : fl) {
System.out.println(element);
}
System.out.println("CHANGE ALL DATA");
Iterator<FishData> itr3 = fl.iterator();
while (itr3.hasNext()) {
FishData b = (FishData) itr3.next();
b.setSpecies(" Shrekfish ");
b.setSeason(" Whenever it wants ");
b.setlimit(300000000);
b.setminSize(900000000);
b.setWillEat(false);
for (FishData element : fl){
System.out.println(element.toString());
}
}
}
}