Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:19:48+00:00 2026-06-12T04:19:48+00:00

I am trying to read data from a file and use the data for

  • 0

I am trying to read data from a file and use the data for testing the procs. Even the proc to be tested is determined from the contents of the file.

Sample.txt is the file from which I read the data, the file contains the following data

testproc=sample_check('N')
output=yes
type=function
testproc=sample_check('N')
output=yes
type=function
testproc=sample_check('N')
output=yes
type=function

The below program tries to read the file and populate its contents into a 2 dimensional String array.

@RunWith(value = Parameterized.class)
public class Testdata extends Testdb {

    public String expected;
    public String actual;

    @Parameters
    public static Collection<String[]> getTestParameters() {
        String param[][] = new String [3][3];
        String temp[] = new String [3];
        int i = 0;
        int j = 0;
        try{
            BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
            String strLine;
            String methodkey       = "testproc";
            String methodtypekey   = "type";
            String methodoutputkey = "output";
            String method = "";
            String methodtype = "";
            String methodoutput = "";

            //Read File Line By Line
            while ((strLine = br.readLine()) != null)
            {
                StringTokenizer st = new StringTokenizer(strLine, "=");
                while(st.hasMoreTokens())
                {
                    String key = st.nextToken();
                    String val = st.nextToken();
                    if (key.trim().equalsIgnoreCase(methodkey))
                    {
                        method = val.trim();
                        temp[j] = "SELECT " + method + " FROM dual";
                        j++;
                    }
                    else if (key.trim().equalsIgnoreCase(methodoutputkey))
                    {
                        methodoutput = val.trim();
                        temp[j] = methodoutput;
                        j++;
                    }
                    else if (key.trim().equalsIgnoreCase(methodtypekey))
                    {
                        methodtype = val.trim();
                        if (methodtype.trim().equalsIgnoreCase("function"))
                        {
                            System.out.println(i + " " + method);
                            param[i] = temp;
                            i++;
                            j = 0;
                        }
                    }
                }

            }
        }
        catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

        return Arrays.asList(param)           ;
    }

    public Testdata(String[] par) {
        this.expected = par[0];
        this.actual = par[1];
    }

    @Test
    public void test_file_data() //throws java.io.IOException
    {
        testString("Output should be"+expected , expected, actual);
    }


}

I receive an error
java.lang.IllegalArgumentException: wrong number of arguments

testString is a method that connects to the database to check if the actual value tallies with the expected result. This takes two string values as argument.

My question is how should
return Arrays.asList(param)
and method
public Testdata(String[] par)
look like?

I tested using this and it works fine but since I read from a file, I want to use an array which needs to be returned using return Arrays.asList

return Arrays.asList(new String[][]{
            { "yes", "SELECT sample_check('N') FROM dual"},
            { "yes", "SELECT sample_check('N') FROM dual"},
            { "yes", "SELECT sample_check('N') FROM dual"}
    })           ;
}

public Testdata(String expected,
                           String actual) {
    this.expected = expected;
    this.actual = actual;
}

Any advice on getting this working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:19:50+00:00Added an answer on June 12, 2026 at 4:19 am

    Your constructor is wrong. You need the same number of parameters that you have items in your String[]

    public Testdata(String[] par) {
        this.expected = par[0];
        this.actual = par[1];
    }
    

    This should be:

    public Testdata(String expected, String actual, String somethingElse) {
        this.expected = expected;
        this.actual = actual;
    }
    

    See the javadoc for Parameterized:

    For example, to test a Fibonacci function, write:

    @RunWith(Parameterized.class)
    public class FibonacciTest {
        @Parameters
        public static List<Object[]> data() {
            return Arrays.asList(new Object[][] {
                    { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 }
            });
        }
    
        private int fInput;
        private int fExpected;
    
        public FibonacciTest(int input, int expected) {
            fInput= input;
            fExpected= expected;
        }
    
        @Test
        public void test() {
            assertEquals(fExpected, Fibonacci.compute(fInput));
        }
    }
    

    Each instance of FibonacciTest will be constructed using the
    two-argument constructor and the data values in the @Parameters
    method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read in some sample data from an XML file in a
I'm trying to use the bash builtin read to read data from a file
I am trying to read data from a .log file and process its contents.
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I'm trying to read data from an xml file and display it in a
I'm trying to read the data from a file that I've saved. This code
I'm trying to read data from a binary file and put it into a
I'm trying to read the data from an XML file, validating it against the
I was trying for the first time to read data from a file, a
I'm trying to read the binary data from a binary file with the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.