diff --git a/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class b/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class index c1aea344efaad2d15b7b062784fd51cef66130cb..2fa5842a0df30e57043402766fb26b3dd70f2198 100644 Binary files a/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class and b/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class differ diff --git a/src/opinion/SocialNetwork.java b/src/opinion/SocialNetwork.java index 6c150410266e4f0e98f5ba53ca571d81e247f964..eb49d9e71c09fb6cdf01a40a912966712b973fc0 100644 --- a/src/opinion/SocialNetwork.java +++ b/src/opinion/SocialNetwork.java @@ -304,13 +304,24 @@ public class SocialNetwork implements ISocialNetwork { if (title == null || title.trim().length() <= 1) { throw new BadEntryException("Error: Title is null or too short"); } + String formattedTitle = title.trim().toLowerCase(); LinkedList<String> result = new LinkedList<>(); + for (Book b : listBook) { if (b.getTitle().toLowerCase().contains(formattedTitle)) { result.add(b.toString()); } } + + for (Film f : listFilm) { + if (f.getTitle().toLowerCase().contains(formattedTitle) + || f.getDirector().toLowerCase().contains(formattedTitle) + || f.getScenarist().toLowerCase().contains(formattedTitle)) { + result.add(f.toString()); + } + } + return result; } diff --git a/src/tests/ConsultItemFilmTest.java b/src/tests/ConsultItemFilmTest.java new file mode 100644 index 0000000000000000000000000000000000000000..59bb273ce08851a7741864f3fbaf709deb7b2b5a --- /dev/null +++ b/src/tests/ConsultItemFilmTest.java @@ -0,0 +1,75 @@ +package tests; + +import exceptions.*; +import opinion.ISocialNetwork; +import opinion.SocialNetwork; + +import java.util.LinkedList; + +public class ConsultItemFilmTest { + + private static int checkConsultItemFilmException(ISocialNetwork sn, String title, Class<?> expectedException, String testId) { + try { + sn.consultItems(title); + System.out.println("Err " + testId + " : Expected exception " + expectedException.getSimpleName() + " was not thrown"); + return 1; + } catch (Exception e) { + if (e.getClass().equals(expectedException)) { + System.out.println("Test " + testId + " passed (caught expected " + expectedException.getSimpleName() + ")"); + return 0; + } else { + System.out.println("Err " + testId + " : Unexpected exception " + e); + e.printStackTrace(); + return 1; + } + } + } + + private static int checkConsultItemFilmResult(ISocialNetwork sn, String title, int expectedSize, String testId) { + try { + LinkedList<String> results = sn.consultItems(title); + if (results.size() == expectedSize) { + System.out.println("Test " + testId + " passed."); + return 0; + } else { + System.out.println("Err " + testId + " : Expected " + expectedSize + " result(s) but got " + results.size()); + return 1; + } + } catch (Exception e) { + System.out.println("Err " + testId + " : Unexpected exception " + e); + e.printStackTrace(); + return 1; + } + } + + public static void main(String[] args) { + ISocialNetwork sn = new SocialNetwork(); + int nbTests = 0; + int nbErrors = 0; + + try { + sn.addMember("cinefan", "securepass", "film fan"); + sn.addItemFilm("cinefan", "securepass", "Interstellar", "Sci-Fi", "Christopher Nolan", "Jonathan Nolan", 169); + sn.addItemFilm("cinefan", "securepass", "Inception", "Thriller", "Christopher Nolan", "Christopher Nolan", 148); + } catch (Exception e) { + System.out.println("Setup failed: " + e); + return; + } + + // Nominal tests + nbTests++; + nbErrors += checkConsultItemFilmResult(sn, "Inception", 1, "3.1"); + + nbTests++; + nbErrors += checkConsultItemFilmResult(sn, "nolan", 2, "3.2"); + + nbTests++; + nbErrors += checkConsultItemFilmResult(sn, "Unknown Film", 0, "3.3"); + + // Non-nominal test (expects exception) + nbTests++; + nbErrors += checkConsultItemFilmException(sn, "", BadEntryException.class, "3.4"); + + System.out.println("\nConsultItemFilmTest summary: " + nbErrors + " error(s) out of " + nbTests + " test(s)."); + } +}