Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Does AssertNotNull take Object[] as one of the parameters?  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was coding something for a problem for school, the testing program took my returned Object[] and stored into another called returnedvalues and then it used assertNotNull("message string",returnedvalues) to check if my returned value is correct (not null). However that generated a type incompatible error which says object[] cannot be converted into string. I was wondering if it was something wrong with the test code. I checked the documentation it says assertnotnull can take a message and an object as a parameter but I am wondering if it still works with a list of objects.
 
Saloon Keeper
Posts: 2276
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using JUnit 4 or JUnit 5?  The order of the parameters is different in JUnit 4 and JUnit 5.

JUnit 5: public static void assertNotNull(Object actual, String message)
JUnit 4: public static void assertNotNull(String message, Object object)
 
Yiren Tu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Are you using JUnit 4 or JUnit 5?  The order of the parameters is different in JUnit 4 and JUnit 5.

JUnit 5: public static void assertNotNull(Object actual, String message)
JUnit 4: public static void assertNotNull(String message, Object object)



Thank you for you reply Ron!
The school server runs the compiler so I can't really tell (I can't see what they imported), but assuming it is JUnit4 can the function take a object array instead of an object as a parameter?
 
Sheriff
Posts: 23970
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, an object array is an object -- all arrays are objects -- so assuming it's JUnit4 then the assertNotNull method can take an object array as its second parameter. And you wouldn't get any compiler error.

But...

Assuming it's JUnit5, using an object array as the second parameter would produce a compiler error, because the compiler would be expecting a String there and not an object array. I believe you were given an error message saying that, were you not?

So that tells me what version of JUnit is being used.
 
Yiren Tu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Yes, an object array is an object -- all arrays are objects -- so assuming it's JUnit4 then the assertNotNull method can take an object array as its second parameter. And you wouldn't get any compiler error.

But...

Assuming it's JUnit5, using an object array as the second parameter would produce a compiler error, because the compiler would be expecting a String there and not an object array. I believe you were given an error message saying that, were you not?

So that tells me what version of JUnit is being used.



Well weird thing is the compiler shows the error exactly where it occurs by a small arrow in the error message and apparently the first parameter is completely fine as it is, which wouldnt make much sense if it is JUnit5 since the parameters are completely switched? Maybe I should include a photo tomorrow this is a strange error xD
 
Yiren Tu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But yeah based on the help I got for now it could be the wrong order they put the test code in.... (I didnt call the assert function in my code, I just need to return a object array) so I will maybe file a report to them.
 
Paul Clapham
Sheriff
Posts: 23970
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yiren Tu wrote:Well weird thing is the compiler shows the error exactly where it occurs by a small arrow in the error message and apparently the first parameter is completely fine as it is, which wouldnt make much sense if it is JUnit5 since the parameters are completely switched?



Sure it makes sense. JUnit5, we know, requires an Object as its first parameter. You're passing a String as the first parameter, and since a String is an Object, that's perfectly fine.

But yeah, I don't think it would hurt to talk to the testing people and ask what version of JUnit they are using.
 
Yiren Tu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:
But yeah, I don't think it would hurt to talk to the testing people and ask what version of JUnit they are using.



Ahh that makes sense, I.just can't believe they coded the test case wrong, I will just ask them about it and hopefully their staff is not taking a break in Hawaii.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!