java - Generics in Hamcrest Matchers -


i not quite sure if problem having has simple solution, here's code excerpt:

 map<?,?> m = dbo.tomap();  assertthat(m, matchers.<object, object>hasentry(is(somekeyvalue), is(notnullvalue()))); 

i have add generics appease compiler, why can't simpler? why have add wildcard capture m variable ? why can't @ least:

 assertthat(dbo.tomap(), hasentry(is((object)somekeyvalue), is(notnullvalue()))); 

here's simple project. in unit test lines bother me:

// 1 doesn't quite work dbobject dbo = returnsomedbobject(); map m3 = dbo.tomap(); assertthat(m3, hasentry(is((object)psf_key), is(notnullvalue())));  // 1 dbobject dbo2 = returnsomedbobject(); map<?,?> m4 = dbo.tomap(); assertthat(m4, matchers.<object, object>hasentry(is(psf_key), is(notnullvalue()))); 

you can use "raw" matcher:

dbobject dbo = returnsomedbobject(); map m3 = dbo.tomap();  assertthat(m3, (matcher)hasentry(is("psf_key"), is(notnullvalue()))); 

by way, can use matchers.haskey method assert map has entry specific key:

assertthat(m3, (matcher)haskey("psf_key")); 

however aware not sementically same first assert when dealing null values in map.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -