• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Distributed Reservation Management System (DRMS) using Java RMI

 
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

As per previous discussion i am starting this project to learn several things. I will add up difficulty as times goes by.

Requirement is as below. I have copied it from somewhere and source is unknown.


In the assignments and project, you are going to implement a simple Distributed Reservation Management System (DRMS) for libraries:

a distributed system to manage a group of library systems used by students and administrators to help them manage book reservations.
So you will need to implement both the student interface support and admin interface support. That is, you need to implement the
functionalities that will help the end users (students and admin, in this case) make use of the reservation system to reserve books
available within the library systems.

Consider a group of libraries each associated with a unique educational institution. The server for each library must maintain a collection
of books. Each book object can be stored in any container of your choice, but make sure the container gives the best efficiency for the
operations related to accessing the book object. The book structure should contain the following fields:

• Name of the book
• Author of the book
• Number of copies available

Students who need to borrow a book from the library must have an account with the server that supports the library. An account contains
the following specific information about the student:

• First Name
• Last Name
• Email Address
• Phone Number
• Unique Username (min 6 characters and max 15 characters)
• Password of at least 6 characters
• Reserved books and duration to return the books
• Fines accumulated
• Educational Institution

The accounts are placed in several lists that are stored in a hash table according to the first character of the username indicated in
the account. For example, all the accounts with the username starting with an “A” will belong to the same list and will be stored in
a hash table (acting as the database) using the key “A”. Each server also maintains a log containing the history of all the operations
that have been performed on that server. This should be an external text file (one per server) and shall provide as much information
as possible about what operations are performed, at what time and who performed the operation.

The system has two distinct types of users:
Students
Administrators.

Students can be identified by their username, password and educational institution. Whenever a student performs an operation,
the system must identify the library that the student belongs to based on his/her educational institution and thus direct all the
operations to that specific server. The students maintain a file (text file) of the actions they performed on the system and the
response from the system when available. For example, if you have 10 students using your system, you should have a folder
containing 10 files.

Administrators can be identified by their username, password and educational institution. For the sake of this assignment all the
administrators have the same username which is “Admin” and the password is also “Admin”. The administrators also maintain a file.

The operations that can be performed are the following:

Operations performed by Students
• createAccount (FirstName, LastName, EmailAddress, PhoneNumber, Username, Password, EducationalInstitution)

When a student invokes this method through a client program called StudentClient, the server associated with the educational institution attempts
to create an account with the information passed if the username does not exist and that the passed information is valid according to the problem
description by inserting the account at the appropriate location in the hash table. The server returns information to the student whether the operation
was successful or not and the student file is created and updated on the server. For simplicity it is assumed that the student has access to creating
an account in the library only if he/she is enrolled in the educational institution.

• reserveBook (Username, Password, BookName, AuthorName)
When a student invokes this method through the client program called the StudentClient, the server associated with this student attempts to find if the book
exist (although the book entry is found, quantity should be greater than 0 to successfully reserve). If it does, then the corresponding quantity is decremented
and the book is updated to the reserved book list of the student. Note that the student has to provide valid credentials to reserve a book. The duration is set
to 14 days by default. Student file is updated.

Operation performed by Administrators

• getNonRetuners (AdminUsername, AdminPassword, EducationalInstitution,NumDays)
When Admin runs the getNonReturners () though the client program AdminClient,
it lists all the students’ First Name, Last Name and Phone Number who have not
returned the books with “NumDays” past their loan date in all the three educational
institutions. The admin File is updated with this information. The admin can then pass that information to the customer care agent to place a call to all the customers

to remind them about the book loan.
For the sake of this assignment, you have to make sure the getNonReturners () functions
returns
Educational Institution 1 : FirstName1 LastName1 514xxxxxxx
FirstName2 LastName2 514xxxxxxx
FirstName3 LastName3 514xxxxxxx
……..
Educational Institution 2 : FirstName1 LastName1 514xxxxxxx
FirstName2 LastName2 514xxxxxxx
FirstName3 LastName3 514xxxxxxx
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to paste my initial design for the same soon. Do you guys have any suggestion, anything to add or remove? I hope i will receive help from you guys
and tried to improve myself.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a cool project! GL
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stijn..
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created some flow diagram for the same. Any suggestion?


Overall_Flow.PNG
[Thumbnail for Overall_Flow.PNG]
Overall flow
Transaction.PNG
[Thumbnail for Transaction.PNG]
Transaction invloved
CreateAccount.PNG
[Thumbnail for CreateAccount.PNG]
Library account creation
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought some of the classes. Please suggest

1) Server end: Library, Book, User (Student and Administrator), Transaction, Customer Care

2) Client end: StudentClient, AdminClient

3) General: Main , Utility , Logger class either from Apache or Java 8


class structure:

Client side:

Interface: StudentClient

Instance Method: createAccount (FirstName, LastName, EmailAddress, PhoneNumber, Username, Password, EducationalInstitution),
reserveBook (Username, Password, BookName, AuthorName) , returnBook(Username, Password, BookName, AuthorName)

Interface: AdminClient
Instance Method: getNonReturnBooksDetail(AdminUsername, AdminPassword, EducationalInstitution,NumDays)

Server Side:

class Book:
Instance Variable: bookName, authorName, numberOfBooksAvailable, numberOfBooksIssued
Instance Method: incrementBookCount(quantity), reduceBookCount(quantity)

class User:
Instance Variable: firstName, lastName, emailAddress, phoneNumber, educationalInstitute
Instance Method: updateEmailAddress(..), updatePhoneNumber(..)

class Student extends User implements StudentClient
Instance Variable: userName, password, reservedBooks<Book, Quantity>, durationOfBookReturn<Book, daysLeftToReturnBook>, finesAccumlated<Book, Fine>, totalFine
Instance Method: createAccount(..), reserveBook(..), returnBook(..), fineCalculation(), daysLeftToReturnBook(),isStudentInSameInsititue(EducationalInstitution)

class Administrator extends User implements AdminClient
Instance Variable: userName = "admin", password = "admin"
Instance Method: getNonReturnBooksDetail(..)

Library:
Instance Variable: storeUserNamesWithStartingAlphabet<Alphabet, List<UserName>, issuedBooked<Book, List<UserName>, totalAvailableBook<Book, originalBookCount>,
Instance Method: isAccountExist(userName), createAccount(Student),

private class UserName in Library class
Instance Variable: userName, password

private class Login in Library class
Instance Method: doLogin(userName, password)
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is problem with the overall flow.. Just wondering Libraries, Library and Server are same. We need to have one class Library for them.
 
Marshal
Posts: 66107
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too large a problem for “beginning”. Moving discussion.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, so should i select some small project?
 
Campbell Ritchie
Marshal
Posts: 66107
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I simply meant you should discuss it on this forum. Now it is on this forum, all is well.

You should consider whether it is the best project or not; that is a separate question. I believe RMI has fallen into disuse, so a change would not be disastrous.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah ok, any suggestion please.
 
Stijn Rensen
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you're considering that the libraries have different physical locations. If that is the case you could consider the whole library as one datasystem and have the physical location a property of the book. In that case you could consider Educational institute, library, libraries and server as one dat object. Being one datasystem with books. That would simplify the thing a whole bit.

If you want to state that all libraries have different databases administrating their books you could still consider it as one black box for the most part. Defining it as one datasystem and make interfaces with the other database. But not sure if you should want this.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stijen.. I am considering second case where all libraries have different databases administrating their books. In the requirement following
is mentioned which is why i thought about 2nd option. But i don't think considering one database system to all the libraries doesn't fit into these?

Consider a group of libraries each associated with a unique educational institution. The server for each library must maintain a collection
of books

 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it should be like one system which controls the several libraries and each library should control the server which having books and account info.
So i suppose each library object is represents to single educational Institute and single server.
 
Stijn Rensen
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that it should be either of the 2:
1. All the different libraries see their database as a master.
2. The new central system is the masterdatabase.

In this case, reading your requirements, with each institute having their own database. I would look at the system as serviceprovider that "borrows" books from the different institutes so it can lend them to the students. As such it such be able to
- Registrate all users that want to make use of the services (aka the students)
- Keep track off all books the where lend via this system from which institutes.
- be able to make borrow and return requests to the instute libraries
- Keep track of student running late in their return

It should not track the inventory off all the libraries (ie making a copy of the other databases). When a users is searching for a book, the system should be able to parse that query via sql onto the different databases.

Greetz


 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stijn, it is exactly i thought about it..

So should i start working on class design? I paste few of them earlier but i think little change is required now.
 
Stijn Rensen
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I think so.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As System class hold all the references to the library and also interface to the Student and admin
so i suppose it implements StudentClient and AdminClient interface.

I thought some of the classes:

StudentClient, AdminClient are the interfaces for student and admin.

System, Library, Book, User (Student and Administrator), Transaction, Customer Care, Main , Utility ,
Logger class either from Apache or Java 8

class structure:

Interface: StudentClient
Instance Method: createAccount (FirstName, LastName, EmailAddress, PhoneNumber, Username, Password, EducationalInstitution),
reserveBook (Username, Password, BookName, AuthorName) , returnBook(Username, Password, BookName, AuthorName)

Interface: AdminClient
Instance Method: getNonReturnBooksDetail(AdminUsername, AdminPassword, EducationalInstitution,NumDays)


System class:
variable: listOfLibraries<Library>, threadPool[numberOfLibraries]
method: createAccount(..), reserveBook(..), returnBook(..), getNonReturnBooksDetail(..)

Library:
Instance Variable: storeUserNamesWithStartingAlphabet<Alphabet, List<UserName>, issuedBooked<Book,
List<UserName>, totalAvailableBook<Book, originalBookCount>,
Instance Method: isAccountExist(userName), createAccount(Student),

private class UserName in Library class
Instance Variable: userName, password

private class Login in Library class
Instance Method: doLogin(userName, password)

Book:
Instance Variable: bookName, authorName, numberOfBooksAvailable, numberOfBooksIssued
Instance Method: incrementBookCount(quantity), reduceBookCount(quantity)

User:
Instance Variable: firstName, lastName, emailAddress, phoneNumber, educationalInstitute
Instance Method: updateEmailAddress(..), updatePhoneNumber(..)

Student
Instance Variable: userName, password, reservedBooks<Book, Quantity>, durationOfBookReturn<Book, daysLeftToReturnBook>, finesAccumlated<Book, Fine>, totalFine
Instance Method: createAccount(..), reserveBook(..), returnBook(..), fineCalculation(), daysLeftToReturnBook(), isStudentInSameInsititue(EducationalInstitution)

Administrator
Instance Variable: userName = "admin", password = "admin"
Instance Method: getNonReturnBooksDetail(..)
 
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion has progressed beyond what fits the Java in General and Beginning Java forums. Moving this to the Design forum.
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen this kind of approach before and it usually ends up being largely a waste of time. It's like you going around and gather a bunch of building materials without having any idea of what kind of thing you want to build. Or like walking around a car parts store and gathering a bunch of random parts without having a clear idea of where you want to go or who and what you're going to take with you and what you'll do when you get there, wherever "there" is.

See this thread: https://coderanch.com/t/643124/design/implement-vending-application for an alternative approach. Basically, I find it's better start by relating what it is you want to do, regardless of technology, and what goals you want to achieve. And having this or that class is not a goal and this or that relationship between classes with this or that cardinality are not "goals"; these are implementation details. You are getting caught up in detailed class designs and formulating ideas of complex relationships between these classes and that's all well and good but these are all just theories. Without working code, there's really no way to test your theories out and see if they work... the proof, as they say, is in the pudding and the pudding is working code and tests that exercise it.

Again, go through https://coderanch.com/t/643124/design/implement-vending-application and see how we organized the goals and ideas, wrote tests to try out those ideas, and refactored along the way to adjust our "theories" based on what we learned from thinking about and writing the tests and the working code every step of the way. I really believe this is a much better way to develop software.
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stijn Rensen wrote:
In this case, reading your requirements, with each institute having their own database. I would look at the system as serviceprovider that "borrows" books from the different institutes so it can lend them to the students. As such it such be able to
- Registrate all users that want to make use of the services (aka the students)
- Keep track off all books the where lend via this system from which institutes.
- be able to make borrow and return requests to the instute libraries
- Keep track of student running late in their return


This is a great place to start. You need to refine them further though. Take the first one, for example. "Register someone who wants to use the services" (reworded a little). Is that a good summary? Is the goal clear? How about if we say:
"As a student, I want to register as a user of the Reservation System so I can take advantage of the various services it offers."

That seems like a complete thought, with a clearly stated goal. How would I test this? How can I tell that this can actually be done? What will the experience of registering as a user of the system be like?

Without clear answers to these questions, focusing on classes and relationships is more than likely to be an exercise in over-engineering.
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I looked back at your original post and perhaps I was too hasty in judging the state of your requirements. There are in fact quite a number of things we can get from this initial description and since this is an exercise, the nature of the writeup is, by necessity, going into many different levels of detail. The first thing I would do is to separate the general ideas from what are actually suggestions for implementation.

Let's take this one: Students who need to borrow a book from the library must have an account with the server that supports the library.

This is related to the one I just went over. The part that says "the server that supports the library" is an implementation suggestion. Why limit ourselves to having one server support each library. What if we wanted to use cloud services? What if there were so many users that you couldn't handle them all in one server? What if ... and so and so forth.

The general idea and goal, however, was what we already stated: "As a student, I want to register with the system so that I can take advantage of services offered." The particular service here is borrowing a book from the library.

So start there and describe what the user's experience should be like. Then you can start looking for responsibilities and behaviors and with that, you can start playing around with ideas about who should be assigned these responsibilities and behaviors.

 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Junillu for wonderful suggestion.

I am still trying to understand your suggestion and the post you referred and once i cleared i will come back.

I suppose you mean that we should first mention the what user wanted to do and what happened when he tried to use it before deciding the responsibility or class.

 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:
I suppose you mean that we should first mention the what user wanted to do and what happened when he tried to use it before deciding the responsibility or class.


In a nutshell, yes. The point of developing software is that someone can benefit from it. Your goal, as Jeff Patton puts it in his book "User Story Mapping," is to Minimize output, and maximize outcome and impact.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu.. I am reading your post right now and your support for TDD. I will definitely come back. Thank you once again..
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu for the wonderful suggestion.. After reading the suggested thread, i realized that i was wrong. So, i am going to start again and hope
to do the things right now.

With the details mentioned in the assignment i thought few of the story points. Please suggest:

Goal: A valid user can avail the functionality provided by the Library which is book reservation

TO Do list:

1) Library contains collections of books
2) Student requires an account in the library in which it is student to avail the service.
3) Student can request for the creation of the account if not available
3) Student can issue the book if available (quantity > 0) with their institute library only
4) Administrator will track the students which didn't return the book

 
Bartender
Posts: 9586
13
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:
Requirement is as below. I have copied it from somewhere and source is unknown.



This requirement sounds very academic, and has actually been discussed at JavaRanch before. I just want to make sure that you are not asking for help with a homework assignment since your instructors probably know how to use Google and this topic is the #1 hit for text from this requirement.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No this is not any homework assignment. Actually for self learning i selected few topics and this was selected as the final result. Yeah i took requirement
from some old posts
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried now to implement using TDD.

I take first point in TODO list

1) Library contains collections of books

So here are my initial code:


Step1:



a) Compilation failure. Red: test fail

b) Create a class library, still compilation problem,
define addBook and size method, run test



Run test, still fail. Change 0 to 1, Run test, Test is now passed.

c) Refactoring: Changed variable name to more meaningful name



 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good that you're starting with a TODO list. That's always a good habit.

The first point that you tackle, however, "Library contains collections of books" is not a statement of something that can be done by someone so they can benefit from the system. It's really just another implementation detail. Think about the Students instead and what one of them would want to do. Come up with a list of things a Student would want to do through this system. And don't think about things like servers or RMI or distributed processing. Just put yourself in the shoes of a Student who knows absolutely nothing about what goes on inside the system. All they know is that the system exists and that it helps them, i.e. they can benefit from it in some way. I'll start you out:

1. Register for a new account
2. Search for books
3. Reserve/borrow books
4. Check out books
5. Return books
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why Student should it be first to implement? If Library doesn't exist then Student can't use any of the service of the library?
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, working on 1 point: Register for a new account

Step 1: Red:



Result : Compilation error as Student class not found and neither the register method, failed

Green:



Result is again failed. Changed false to true. Now result is passed.

Refactor: Removed auto comments.


 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think above mentioned point should not be first step. First step is to take the student details which is below:

Step 2: Add the student details:




Test failed due to compilation error.

Defined "addDetail" method in Student class:



Test is now failed. Changed false to true and test is now successful. Time to do re-factoring(name are not good) . Again run the test now. It is Green.



ToDoList Now:

1) Check for Null value
2) Check for Zero length values
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:But why Student should it be first to implement? If Library doesn't exist then Student can't use any of the service of the library?


That's not what I was trying to say. I'm talking about the perspective from which you view the system. You were viewing it from an Engineer's perspective by thinking about the Library as a collection of books and what not. I was saying another perspective is from the Student's side. This may or may not involved writing a Student class. Or you could start with Library first, except this time, you might want to work out what responsibility/role the Library class will play in getting a Student registered.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I started to work on Student class. Pasted some test cases for it. Any suggestion?
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ok, let's back up first.

The package name doesn't have to be test. In fact, test classes should be in the same package as the class they are testing. I use Maven most of the time when I write Java programs and Maven's project structure looks something like this:

Next, let's look at your API:

To me, the story this tells is like this:

Does that make sense? What about:

Which story do you think makes more sense?
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah 2nd story is corrected...

So you mean i have to do something like this?


 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good, small step forward. But see, the story that your test tells still doesn't make much sense.

If you are asserting something regarding the Library, (Line 19), why is this test called "StudentTest"?

Why is the method (line 18) called registerMyself?

Why are you creating a Student on lines 16-17 and not even using it in the test?

My translation of the story that I gave earlier would be something like this:

Read that out loud. Doesn't that make a lot more sense?

The white spaces in the test method creates visual separation between the sections of a test following the 3A pattern: Arrange, Act, Assert (see Bill Wake's 3A test pattern)

Now you have an API that makes a little bit more sense. Now you can go and write some production code.
 
Junilu Lacar
Marshal
Posts: 14234
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are Three Rules of TDD:

1. You will not write any production code unless you have a failing test

2. You will not write more test code than is sufficient to fail

3. You will not write more production code than is sufficient to make a failing test pass

You don't have to follow these rules strictly all the time although doing so will keep you focused on writing only the code that you need at the moment.

These lines of code are not needed and writing them violates rule #2:

You are prematurely and misguidedly trying to optimize the test with this code in the setUp method. The @Before annotation causes JUnit to execute the method before every test method. So the check for isSetUpDone is actually pointless, as is your static boolean declaration of the variable.

Declaring the library instance variable, also known in unit tests as a "fixture", is premature at this point. There's nothing in the test code that gives you the motivation to do this yet. Once you write more test code and you start duplicating the statement to instantiate a Library, then you'll have the motivation. Don't preempt the refactoring until the code tells you though. Let the code guide you into what you should do next.
 
Tushar Goel
Ranch Hand
Posts: 952
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you are asserting something regarding the Library, (Line 19), why is this test called "StudentTest"?


Point noted. Thanks.

Why is the method (line 18) called registerMyself?


I was thinking that library itself not registered any student. In real time Student request librarian or whatever admin is that s/he wanted to open an account.
On receiving such request account is opened. So yes library.registerMyself() is wrong, i suppose it should be student.registerMyselfToLibrary() but
whatever you are saying is also looking correct as library is only one who will create an account. I am confused here. Please guide.

Thanks for telling about 3A and TDD rules. I will take for Fixture as well next time.

Let the code guide you into what you should do next.


I suppose it required lot of practise and patience. Thanks again.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!