Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JUnit Testing question  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to java and JUnit testing altogether so please forgive me if this is a stupid question.

I am trying to setup my variable of a particular object type which happens to be an array as follows:

static QueryParameter[] READ_REQUEST_QUERY = {hospcode, =, HAR};

The error that I am getting for the static statement above is:
Syntax error on token "=", invalid VariableInitializer

The "QueryParameter[]" is defined as follows:

public void setQuery(org.texashealth.www.SCM.DataTier.Common.QueryParameter[] query) {
this.query = query;
}

query will contain: a fieldname, a value and a comparison operator.

I do not understand this error and wondered if someone could please give me some direction or help.

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's that second array item there:

static QueryParameter[] READ_REQUEST_QUERY = {hospcode, =, HAR};

the equals sign '=' is not an instance of QueryParameter, but that's what the compiler wants here. I can't tell what you're trying to do, so I can't tell you how to fix it; but do you see what's wrong now?
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest,

Thanks for the reply. I am having to pass into this array a fieldname, operator and value (like a WHERE clause in a sql statement).

Hope that makes sense.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Let's see, though: the array is of type QueryParameter[], which means every item in this initializer list has to be a QueryParameter object. I don't know what "hospCode" and "HAR" are -- are they instances of this class? If they are, then that's fine; if they're not, then as soon as we fix this problem, the compiler will start reporting those.

So, in any case, I have no idea how to construct a QueryParameter, but let's say it has a constructor that takes a single String as an argument. Then maybe you want (assuming hospcode and HAR are variables of type QueryParameter already

static QueryParameter[] READ_REQUEST_QUERY = {hospcode, new QueryParameter("="), HAR};
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest,

Thanks again for the help and your time. The list (hospcode, har, =) are values to pass into this array that will be used in a WHERE clause when I break it out of this array by element in my code but for testing purposes I am trying to hardcode everything because I do not yet have access to our mainframe database and so I just working off of my personal edition sql server on my desktop.

Thanks again.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is more a problem of basic Java syntax than testing, therefore moving to Java in General (beginners)...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!