Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sample.springboot;
- import java.util.ArrayList;
- import java.util.List;
- public class BookStore { //★テスト対象クラス
- private List<Cart> cart = new ArrayList<Cart>();
- private List<Book> books = new ArrayList<Book>();
- public void addToCart(Book book, int i) {
- books.add(book);
- Cart item = new Cart(book, i);
- cart.add(item);
- }
- public int getTotalPrice() {
- int sum = 0;
- for (Cart Cart : cart) {
- int priceOne = Cart.getBook().getPrice();
- sum += priceOne * Cart.getCount();
- }
- return sum;
- }
- public Book get(int i) {
- return books.get(i);
- }
- }
- class Cart { //★テスト対象クラスが利用しているクラス
- private Book book;
- private int count;
- public Book getBook() {
- return book;
- }
- public void setBook(Book book) {
- this.book = book;
- }
- public int getCount() {
- return count;
- }
- public void setCount(int count) {
- this.count = count;
- }
- public Cart(Book book, int count) {
- super();
- this.book = book;
- this.count = count;
- }
- }
- class Book { //★テスト対象クラスが利用しているクラス
- private String title;
- private int price;
- private Author author;
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public int getPrice() {
- return price;
- }
- public void setPrice(int price) {
- this.price = price;
- }
- public Author getAuthor() {
- return author;
- }
- public void setAuthor(Author author) {
- this.author = author;
- }
- public Book() {
- super();
- }
- public Book(int price) {
- this();
- this.price = price;
- }
- }
- class Author { //★テスト対象クラスが利用しているクラス
- private String firstName;
- private String lastName;
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- }
Add Comment
Please, Sign In to add comment