Mam taki kod:
public class Lista {
ElementListy poczatek;
Lista(ElementListy poczatek) {
this.poczatek = poczatek;
}
Lista(int poczatkowaDlugoscListy) {
poczatek = new ElementListy(poczatkowaDlugoscListy);
}
public void wypiszLista() {
/*
* Wypisuje na standardowe wyjście kolejne elementy listy
*/
ElementListy akt = poczatek;
while (akt != null) {
akt.wypiszElement();
akt = akt.nast;
}
}
}
public class ElementListy {
String atrybut;
ElementListy nast;
public ElementListy(String atrybut) {
this.atrybut = atrybut;
this.nast = null;
}
public ElementListy(int poczatkowaDlugosc) {
/*
* Tworzy kolejne elementy listy pobierając ze standardowego wejścia
* kolejne napisy, które stają się atrybutami elementów listy.
*/
if (poczatkowaDlugosc > 1) {
Scanner wejscie = new Scanner(System.in);
this.atrybut = wejscie.next();
this.nast = new ElementListy(poczatkowaDlugosc-1);
}
else if (poczatkowaDlugosc == 1) {
Scanner wejscie = new Scanner(System.in);
this.atrybut = wejscie.next();
this.nast = null;
}
else {
this.atrybut = null;
this.nast = null;
}
}
}
Chcę używając testów generowanych przez program NetBeans spawdzić czy działa np wypisywanie Listy. Problem w tym, że jak tworzę obiekt typu Lista, to przy testowaniu nie jestem proszony o podanie danych i przez to powstanie błąd (NoSuchElementException).