assertThat() method failing - compilation error

752 views
Skip to first unread message

smk

unread,
Jun 14, 2012, 3:17:37 AM6/14/12
to hamcre...@googlegroups.com
Hi, 

I am trying to use the hamcrest assertThat() for my tests and getting errror.

Code : 

    public void shouldProcessMutualFundNavGivenNavList() throws IOException {
        //given
        MarketService marketService = new MarketService();
        marketService.setMutualFundNav(mutualFundNav);

        //when
        ArrayList<String[]> navList = marketService.retrieveLatestNavList();

        //then
        assertThat(navList, is(notNullValue()));
    }


Error : 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
3.2:testCompile (default-testCompile) on project ManageMyMoney-web: Compilation
failure: Compilation failure:
[ERROR] \xyz\workspaces\ManageMyMoney\web\src\test\java\com\mmm\service\Mark
etServiceIntegrationTest.java:[8,26] cannot find symbol
[ERROR] symbol  : class MatcherAssert
[ERROR] location: package org.hamcrest
[ERROR] \xyz\workspaces\ManageMyMoney\web\src\test\java\com\mmm\service\Mark
etServiceIntegrationTest.java:[8,0] static import only from classes and interfac
es
[ERROR] \xyz\workspaces\ManageMyMoney\web\src\test\java\com\mmm\service\Mark
etServiceIntegrationTest.java:[37,8] cannot find symbol
[ERROR] symbol  : method assertThat(java.util.ArrayList<java.lang.String[]>,org.
hamcrest.Matcher<java.lang.Object>)
[ERROR] location: class com.mmm.service.MarketServiceIntegrationTest


scarytom

unread,
Jun 16, 2012, 4:49:11 AM6/16/12
to hamcre...@googlegroups.com
Sadly, you are being bitten by the Java type system, which is the source of many difficulties in using hamcrest.

In your case, you can get your code compiling by making the following change:

        //when
        Object navList = marketService.retrieveLatestNavList();


-Tom

Steve Freeman

unread,
Jun 16, 2012, 7:35:32 AM6/16/12
to hamcre...@googlegroups.com
in this case, you might be better to use the Junit assertNotNull()

S.
Reply all
Reply to author
Forward
0 new messages