0

Here is my code

import org.junit.Test;

import static org.junit.Assert.assertThat;
import static sun.nio.cs.Surrogate.is;

public class PlayerTest {
  public void should_return_3_when_status_is_3(){
        Player player = new Player();
        assertThat(player.getStatus(),is(3));
    }
}

And here is the trace

Can't find symbol
符号: method assertThat(int,boolean)
位置: class PlayerTest

my iml file is

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module-library" scope="TEST">
      <library>
        <CLASSES>
          <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
      </library>
    </orderEntry>
  </component>
</module>

I think I used it before,but it not works now. Have no clue about what to do.However assertTrue is working. Ubuntu 11.04 is being used.

Cephalopod
  • 14,632
  • 7
  • 51
  • 70
Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57

1 Answers1

2

The mistake is in

import static sun.nio.cs.Surrogate.is;

is() should return a matcher, but whatever this is, it returns boolean. Try org.hamcrest.Matchers.is or org.hamcrest.CoreMatchers.is instead.

Cephalopod
  • 14,632
  • 7
  • 51
  • 70
  • I tried `org.hamcrest.CoreMatchers.is` and `org.hamcrest.Matchers.is` but it's still says can't find.Should I change the setting of the project? – Shihe Zhang Feb 13 '13 at 04:57
  • @ShiheZhang - Update your question with your latest code because this answer should do the trick. – David Harkness Feb 13 '13 at 06:13
  • Can't find symbol symbol: class is position: class org.hamcrest.CoreMatchers Can't find symbol symbol: method is(int) position: class PlayerTest – Shihe Zhang Feb 14 '13 at 02:21
  • @DavidHarkness I deleted `import static sun.nio.cs.Surrogate.is;` and add `org.hamcrest.CoreMatchers.is` instead. – Shihe Zhang Feb 14 '13 at 02:24
  • @ShiheZhang - I don't see a change to the original question, and the new error message suggests that `is` isn't being imported. Does the new import statement show an error? – David Harkness Feb 14 '13 at 03:41