-
November 21st, 2014, 02:52 AM
#1
Question for my code and JUnit Test
Hi..!
Sorry for my English first..!!!
I have written this class and i don't know who read from a text line by line, split the words and save them in fileOnTable.. Now i don't know what to write in ReadOffer to save the words in object offers and return this..
One more question.. What JUnit Test can i write for that code..?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.example.crazysellout.Offer;
//Class that, reads the file of the data.
public class OfferDataReader {
String[] fileOnTable;
Offer ReadOffer(int indexLine){
Offer offers = new Offer();
offers.StoreName = fileOnTable[0];
offers.ProductCategory = fileOnTable[1];
offers.ProductName = fileOnTable[2];
offers.ProductPrice = fileOnTable[3];
offers.ProductDescription = fileOnTable[4];
return offers;
}
//initialize txt reader with the input stream to set fileOnTable
public OfferDataReader(InputStream iStream) throws IOException {
super();
this.readDataFile(iStream);
}
//Method that reads the text file from resources and
public void readDataFile(InputStream iStream) throws IOException {
//String that gets each line of the text file in a while loop
String stringContainer = null;
//Variable in which the contex of the file will be stored
StringBuffer strBuffer = new StringBuffer();
//Reads each line from the file.
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
while ((stringContainer = reader.readLine()) != null) {
strBuffer.append(stringContainer + "\n" );
}
iStream.close();
textIndexOnTable(strBuffer.toString());
}
//Method that separates the string buffer to lines, and saves
//on a table so that they can be identified as an account.
public void textIndexOnTable(String indexOnString){
fileOnTable = indexOnString.split("\r\n|\r|\n");
}
//Method that breaks each line of the table in offers
public void SplitLines (String splitLinesOnTable){
fileOnTable = splitLinesOnTable.split(" ");
}
}
-
November 21st, 2014, 07:29 AM
#2
Re: Question for my code and JUnit Test
Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.example.crazysellout.Offer;
//Class that, reads the file of the data.
public class OfferDataReader {
String[] fileOnTable;
Offer ReadOffer(int indexLine){
Offer offers = new Offer();
offers.StoreName = fileOnTable[0];
offers.ProductCategory = fileOnTable[1];
offers.ProductName = fileOnTable[2];
offers.ProductPrice = fileOnTable[3];
offers.ProductDescription = fileOnTable[4];
return offers;
}
//initialize txt reader with the input stream to set fileOnTable
public OfferDataReader(InputStream iStream) throws IOException {
super();
this.readDataFile(iStream);
}
//Method that reads the text file from resources and
public void readDataFile(InputStream iStream) throws IOException {
//String that gets each line of the text file in a while loop
String stringContainer = null;
//Variable in which the contex of the file will be stored
StringBuffer strBuffer = new StringBuffer();
//Reads each line from the file.
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
while ((stringContainer = reader.readLine()) != null) {
strBuffer.append(stringContainer + "\n" );
}
iStream.close();
textIndexOnTable(strBuffer.toString());
}
//Method that separates the string buffer to lines, and saves
//on a table so that they can be identified as an account.
public void textIndexOnTable(String indexOnString){
fileOnTable = indexOnString.split("\r\n|\r|\n");
}
//Method that breaks each line of the table in offers
public void SplitLines (String splitLinesOnTable){
fileOnTable = splitLinesOnTable.split(" ");
}
}
-
November 21st, 2014, 09:56 AM
#3
Re: Question for my code and JUnit Test
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|