import de.uni_due.s3.jack2.backend.checkers.tracingchecker.framework.TracingFramework; import de.uni_due.s3.jack2.backend.checkers.tracingchecker.framework.TracingFramework.Test; public class Tests { private int points = 0; public int getResult() { return points; } private int testBook(String title, Person author, int yearOfPublication) { Book b = new Book(title, author, yearOfPublication); final String firstName = author.getFirstName(); final String surname = author.getSurname(); final String info = b.getInfo(); final String perfectMatch = firstName + " " + surname + ": " + title + " (" + yearOfPublication + ")"; if (info != null && perfectMatch.equals(info)) return 40; TracingFramework.printError("Die erwartete Ausgabe ist: " + perfectMatch + " , aber deine Ausgabe ist: " + info); if (info == null) return 0; String whiteSpaceMessed = "\\s*" + firstName + "\\s*" + surname + "\\s*:\\s*" + title + "\\s*\\(\\s*" + yearOfPublication + "\\s*\\)\\s*"; if (info.matches(whiteSpaceMessed)) { TracingFramework.printError("Die Ausgabe hat eine fehlerhafte Anzahl von whitespaces"); return 39; } String rightOrderWithoutSpecialChars = ".*" + firstName + ".*" + surname + ".*" + title + ".*" + yearOfPublication + ".*\\).*"; if (info.matches(rightOrderWithoutSpecialChars)) { TracingFramework.printError("Die Ausgabe gibt die gewollten Eigenschaften nur in der richtigen Reihenfolge aus."); return 30; } return (info.contains(firstName) ? 5 : 0) + (info.contains(surname) ? 5 : 0) + (info.contains(title) ? 5 : 0) + (info.contains(Integer.toString(yearOfPublication)) ? 5 : 0); } @Test(name = "Testfall 1") public void test1() { points += testBook( "The Hitchhiker's Guide to the Galaxy", new Person("Douglas", "Adams"), 1979); } @Test(name = "Testfall 2") public void test2() { points += testBook( "Romeo and Juliet", new Person("William", "Shakespeare"), 1597); } @Test(name = "Testfall 3") public void test3() { Person author = new Person("A", "B"); final int yearOfPublication = 1981; Book b = new Book("Title", author, yearOfPublication); if (b.getAge() == 2016 - yearOfPublication) points += 20; else TracingFramework.printError("Die getAge() Methode errechnet nicht das korrekte Alter. Sie gibt " + b.getAge() + " für ein " + yearOfPublication + " erschienenes Buch zurück."); } }