Skip to content

Commit

Permalink
Rename some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mapu77 committed Jul 20, 2018
1 parent ad7c7dd commit 114293f
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 92 deletions.
36 changes: 18 additions & 18 deletions src/main/java/com/twu/biblioteca/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import com.twu.biblioteca.accounts.infrastructure.AccountPresenter;
import com.twu.biblioteca.accounts.infrastructure.persistence.InMemoryAccountRepository;
import com.twu.biblioteca.authentication.application.Authenticator;
import com.twu.biblioteca.authentication.infrastructure.AuthenticatorInputController;
import com.twu.biblioteca.authentication.infrastructure.AuthenticatorInput;
import com.twu.biblioteca.authentication.infrastructure.AuthenticatorPresenter;
import com.twu.biblioteca.authentication.infrastructure.InvalidLibraryNumber;
import com.twu.biblioteca.authentication.infrastructure.persistence.InMemoryAccessRepository;
import com.twu.biblioteca.books.application.BookRepository;
import com.twu.biblioteca.books.application.BookShelvesInteractor;
import com.twu.biblioteca.books.infrastructure.BookInputController;
import com.twu.biblioteca.books.application.BookShelves;
import com.twu.biblioteca.books.infrastructure.BookInput;
import com.twu.biblioteca.books.infrastructure.BookPresenter;
import com.twu.biblioteca.books.infrastructure.persistence.InMemoryBookRepository;
import com.twu.biblioteca.movies.application.MovieShelvesInteractor;
import com.twu.biblioteca.movies.infrastructure.MovieInputController;
import com.twu.biblioteca.movies.application.MovieShelves;
import com.twu.biblioteca.movies.infrastructure.MovieInput;
import com.twu.biblioteca.movies.infrastructure.MoviePresenter;
import com.twu.biblioteca.movies.infrastructure.persistance.InMemoryMovieRepository;

Expand All @@ -38,19 +38,19 @@ public class App {

public static void main(String[] args) {
AppPresenter appPresenter = new AppPresenter(System.out);
AppInputController user = new AppInputController(System.in);
UserInput userInput = new UserInput(System.in);

BookShelvesInteractor bookShelves = new BookShelvesInteractor(bookRepository);
BookInputController bookInputController = new BookInputController(System.in);
BookShelves bookShelves = new BookShelves(bookRepository);
BookInput bookInput = new BookInput(System.in);
BookPresenter bookPresenter = new BookPresenter(bookShelves, System.out);

MovieInputController movieInputController = new MovieInputController(System.in);
MovieShelvesInteractor movieShelves = new MovieShelvesInteractor(movieRepository);
MovieInput movieInput = new MovieInput(System.in);
MovieShelves movieShelves = new MovieShelves(movieRepository);
MoviePresenter moviePresenter = new MoviePresenter(movieShelves, System.out);

appPresenter.sayWelcome();

AuthenticatorInputController authenticatorInputController = new AuthenticatorInputController(System.in);
AuthenticatorInput authenticatorInput = new AuthenticatorInput(System.in);
Authenticator authenticator = new Authenticator(accessRepository);
AuthenticatorPresenter authenticatorPresenter = new AuthenticatorPresenter(authenticator, System.out);

Expand All @@ -59,36 +59,36 @@ public static void main(String[] args) {
while (account == null) {
try {
appPresenter.askForLibraryNumber();
String libraryNumber = authenticatorInputController.entersLibraryNumber();
String libraryNumber = authenticatorInput.entersLibraryNumber();
appPresenter.askForPassword();
String password = authenticatorInputController.entersPassword();
String password = authenticatorInput.entersPassword();
if (authenticatorPresenter.canAccess(libraryNumber, password)) account = libraryNumber;
} catch (InvalidLibraryNumber e) {
authenticatorPresenter.warnInvalidLibraryNumber();
}
}
appPresenter.showMenu();
while (!user.wantsToExit()) {
switch (user.getSelectedOption()) {
while (!userInput.wantsToExit()) {
switch (userInput.getSelectedOption()) {
case 1:
bookPresenter.listAvailableBooks();
break;
case 2:
bookPresenter.askForBookCheckOut();
String bookTitle = bookInputController.readBookTitle();
String bookTitle = bookInput.readBookTitle();
bookPresenter.checkOutBook(bookTitle);
break;
case 3:
bookPresenter.askForBookReturn();
bookTitle = bookInputController.readBookTitle();
bookTitle = bookInput.readBookTitle();
bookPresenter.returnBook(bookTitle);
break;
case 4:
moviePresenter.listAvailableMovies();
break;
case 5:
moviePresenter.askForMovieCheckOut();
String movieName = movieInputController.readMovieName();
String movieName = movieInput.readMovieName();
moviePresenter.checkOutMovie(movieName);
break;
case 6:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.io.InputStream;
import java.util.Scanner;

class AppInputController {
class UserInput {
private final Scanner scanner;
private Integer selectedOption;

AppInputController(InputStream inputScanner) {
UserInput(InputStream inputScanner) {
this.scanner = new Scanner(inputScanner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.io.InputStream;
import java.util.Scanner;

public class AuthenticatorInputController {
public class AuthenticatorInput {

private final Scanner scanner;

public AuthenticatorInputController(InputStream in) {
public AuthenticatorInput(InputStream in) {
this.scanner = new Scanner(in);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.twu.biblioteca.books.application;

import com.twu.biblioteca.books.core.BookInfo;
import com.twu.biblioteca.books.core.Book;

import java.util.Collection;
import java.util.Optional;

public interface BookRepository {
Collection<BookInfo> listBooks();
Collection<Book> listBooks();

Optional<BookInfo> find(String bookTitle);
Optional<Book> find(String bookTitle);
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package com.twu.biblioteca.books.application;

import com.twu.biblioteca.books.core.BookInfo;
import com.twu.biblioteca.books.core.Book;

import java.util.Collection;
import java.util.Optional;

public class BookShelvesInteractor {
public class BookShelves {

private final BookRepository bookRepository;

public BookShelvesInteractor(BookRepository bookRepository) {
public BookShelves(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}

public Collection<BookInfo> listBooks() {
public Collection<Book> listBooks() {
return this.bookRepository.listBooks();
}

public void checkOut(String bookTitle) {
Optional<BookInfo> book = this.bookRepository.find(bookTitle);
Optional<Book> book = this.bookRepository.find(bookTitle);
if (book.isPresent()) book.get().checkOut();
else throw new BookNotFound();
}

public void returnBook(String bookTitle) {
Optional<BookInfo> book = this.bookRepository.find(bookTitle);
Optional<Book> book = this.bookRepository.find(bookTitle);
if (book.isPresent()) book.get().returnCopy();
else throw new BookNotFound();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.twu.biblioteca.books.core;

public class BookInfo {
public class Book {

private final String title;
private String authorName;
private int publicationYear;
private boolean checkedOut;

BookInfo(String title) {
Book(String title) {
this.title = title;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/twu/biblioteca/books/core/BookInfoBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public BookInfoBuilder publishedInYear(int year) {
return this;
}

public BookInfo build() {
BookInfo bookInfo = new BookInfo(title);
bookInfo.setAuthorName(this.author);
bookInfo.setPublicationYear(this.publicationYear);
bookInfo.setCheckedOut(checkedOut);
return bookInfo;
public Book build() {
Book book = new Book(title);
book.setAuthorName(this.author);
book.setPublicationYear(this.publicationYear);
book.setCheckedOut(checkedOut);
return book;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.InputStream;
import java.util.Scanner;

public class BookInputController {
public class BookInput {
private final Scanner scanner;

public BookInputController(InputStream inputStream) {
public BookInput(InputStream inputStream) {
this.scanner = new Scanner(inputStream);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.twu.biblioteca.books.infrastructure;

import com.twu.biblioteca.books.application.BookNotFound;
import com.twu.biblioteca.books.application.BookShelvesInteractor;
import com.twu.biblioteca.books.core.BookInfo;
import com.twu.biblioteca.books.application.BookShelves;
import com.twu.biblioteca.books.core.Book;
import com.twu.biblioteca.books.core.BookNotAvailable;
import com.twu.biblioteca.books.core.NotAbleToReturnBook;

Expand All @@ -20,10 +20,10 @@ public class BookPresenter {
private static final String THANK_YOU_FOR_RETURNING = "Thank you for returning the book";
private static final String NOT_VALID_BOOK = "That is not a valid book to return";

private final BookShelvesInteractor bookShelves;
private final BookShelves bookShelves;
private final PrintStream output;

public BookPresenter(BookShelvesInteractor bookShelves, PrintStream output) {
public BookPresenter(BookShelves bookShelves, PrintStream output) {
this.bookShelves = bookShelves;
this.output = output;
}
Expand All @@ -37,13 +37,13 @@ public void askForBookCheckOut() {
}

public void listAvailableBooks() {
Collection<BookInfo> books = bookShelves.listBooks();
List<BookInfo> availableBooks = books.stream().filter(BookInfo::isAvailable).collect(Collectors.toList());
Collection<Book> books = bookShelves.listBooks();
List<Book> availableBooks = books.stream().filter(Book::isAvailable).collect(Collectors.toList());
if (availableBooks.isEmpty()) output.println("There are no books in the shelves");
else {
output.println(HEADERS);
for (BookInfo bookInfo : availableBooks) {
output.println(bookInfo.getTitle() + SPACE_BETWEEN_COLUMNS + bookInfo.getAuthorName() + SPACE_BETWEEN_COLUMNS + bookInfo.getPublicationYear());
for (Book book : availableBooks) {
output.println(book.getTitle() + SPACE_BETWEEN_COLUMNS + book.getAuthorName() + SPACE_BETWEEN_COLUMNS + book.getPublicationYear());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.twu.biblioteca.books.infrastructure.persistence;

import com.twu.biblioteca.books.application.BookRepository;
import com.twu.biblioteca.books.core.BookInfo;
import com.twu.biblioteca.books.core.Book;
import com.twu.biblioteca.books.core.BookInfoBuilder;

import java.util.Collection;
Expand All @@ -11,24 +11,24 @@
import java.util.stream.Collectors;

public class InMemoryBookRepository implements BookRepository {
private Map<String, BookInfo> books;
private Map<String, Book> books;

public InMemoryBookRepository(Collection<String[]> books) {
this.books = books.stream().collect(Collectors.toMap(mapKey(),
mapBook()));
}

@Override
public Collection<BookInfo> listBooks() {
public Collection<Book> listBooks() {
return this.books.values();
}

@Override
public Optional<BookInfo> find(String bookTitle) {
public Optional<Book> find(String bookTitle) {
return this.books.values().stream().filter(book -> book.getTitle().equals(bookTitle)).findFirst();
}

private Function<String[], BookInfo> mapBook() {
private Function<String[], Book> mapBook() {
return values -> new BookInfoBuilder().withTitle(values[0]).fromAuthor(values[1]).publishedInYear(Integer.parseInt(values[2])).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Collection;
import java.util.Optional;

public class MovieShelvesInteractor {
public class MovieShelves {

private final MovieRepository movieRepository;

public MovieShelvesInteractor(MovieRepository movieRepository) {
public MovieShelves(MovieRepository movieRepository) {
this.movieRepository = movieRepository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.InputStream;
import java.util.Scanner;

public class MovieInputController {
public class MovieInput {
private final Scanner scanner;

public MovieInputController(InputStream in) {
public MovieInput(InputStream in) {
this.scanner = new Scanner(in);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.twu.biblioteca.movies.infrastructure;

import com.twu.biblioteca.movies.application.MovieNotFound;
import com.twu.biblioteca.movies.application.MovieShelvesInteractor;
import com.twu.biblioteca.movies.application.MovieShelves;
import com.twu.biblioteca.movies.core.Movie;
import com.twu.biblioteca.movies.core.MovieNotAvailable;

Expand All @@ -18,10 +18,10 @@ public class MoviePresenter {
private static final String THANK_YOU_FOR_CHECKING_OUT = "Thank you! Enjoy the movie";
private static final String MOVIE_NOT_AVAILABLE = "That movie is not available";

private final MovieShelvesInteractor movieShelves;
private final MovieShelves movieShelves;
private final PrintStream output;

public MoviePresenter(MovieShelvesInteractor movieShelves, PrintStream output) {
public MoviePresenter(MovieShelves movieShelves, PrintStream output) {
this.movieShelves = movieShelves;
this.output = output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class AppInputControllerShould {
public class UserInputShould {

private AppInputController inputController;
private UserInput inputController;

@Test
public void returnTrueWhenUserWantsToExit() {
System.setIn(new ByteArrayInputStream("0".getBytes()));
inputController = new AppInputController(System.in);
inputController = new UserInput(System.in);
assertThat(inputController.wantsToExit(), is(true));
}

@Test
public void returnFalseWhenUserDoesNotWantToExit() {
System.setIn(new ByteArrayInputStream("1".getBytes()));
inputController = new AppInputController(System.in);
inputController = new UserInput(System.in);
assertThat(inputController.wantsToExit(), is(false));
}

@Test
public void keepSelectedOptionWhenAskingIfUserWantsToExit() {
System.setIn(new ByteArrayInputStream("34".getBytes()));
inputController = new AppInputController(System.in);
inputController = new UserInput(System.in);
inputController.wantsToExit();
assertThat(inputController.getSelectedOption(), is(not(nullValue())));
}
Expand Down
Loading

0 comments on commit 114293f

Please sign in to comment.