dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Question for my code and JUnit Test

Hybrid View

  1. #1
    Join Date
    Nov 2014
    Posts
    2

    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(" ");
    }
    }

  2. #2
    Join Date
    Nov 2014
    Posts
    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(" ");
    	}
    }

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)