You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
package com.rental.crawler;
|
|
|
|
import com.rental.crawler.command.AnalyzeCommand;
|
|
import com.rental.crawler.model.Book;
|
|
import com.rental.crawler.repository.ArticleRepository;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
System.out.println("========== 测试 ArticleRepository addAll ==========");
|
|
ArticleRepository repository = new ArticleRepository();
|
|
|
|
List<Book> books1 = new ArrayList<>();
|
|
books1.add(createBook("书1", "作者1", "出版社A", 8.5));
|
|
books1.add(createBook("书2", "作者2", "出版社B", 7.5));
|
|
books1.add(null);
|
|
repository.addAll(books1);
|
|
System.out.println("添加book1后的数量: " + repository.size());
|
|
|
|
List<Book> books2 = null;
|
|
repository.addAll(books2);
|
|
System.out.println("添加null后的数量: " + repository.size());
|
|
|
|
repository.add(null);
|
|
System.out.println("添加单个null后的数量: " + repository.size());
|
|
|
|
List<Book> books3 = new ArrayList<>();
|
|
books3.add(null);
|
|
books3.add(createBook("书3", "作者3", "出版社C", 9.0));
|
|
repository.addAll(books3);
|
|
System.out.println("添加包含null的列表后的数量: " + repository.size());
|
|
|
|
System.out.println("\n========== 测试 AnalyzeCommand ==========");
|
|
List<Book> testBooks = new ArrayList<>();
|
|
testBooks.add(createBook("红楼梦", "曹雪芹", "人民文学出版社", 9.0));
|
|
testBooks.add(createBook("水浒传", "施耐庵", "上海译文出版社", 8.5));
|
|
testBooks.add(createBook("书3", "作者3", "未知出版社", 6.5));
|
|
testBooks.add(null);
|
|
|
|
AnalyzeCommand analyzeCommand = new AnalyzeCommand();
|
|
analyzeCommand.execute(testBooks);
|
|
|
|
System.out.println("\n测试完成!");
|
|
}
|
|
|
|
private static Book createBook(String title, String author, String publisher, double rating) {
|
|
Book book = new Book();
|
|
book.setTitle(title);
|
|
book.setAuthors(author);
|
|
book.setPublisher(publisher);
|
|
book.setRating(rating);
|
|
return book;
|
|
}
|
|
}
|