Eric B.
Eric B.

Reputation: 24411

Hamcrest matching enum values?

I'm probably missing something very obvious here and when I see it, I'll smack myself.

I'm trying to test the output of a method which returns an Enum with Hamcrest:

@Test
public void testGetBuildInfo() throws Exception {
    BuildType build = repository.getBuildInfo(169552, null, 582892L);
    assertThat(build.getPolicyComplianceStatus(), IsEqual.equalTo(PolicyComplianceType.DID_NOT_PASS));
}

but I am getting the folliwng error:

The method assertThat(T, Matcher<? super T>) in the type MatcherAssert is not applicable for the arguments (PolicyComplianceType, Matcher<PolicyComplianceType>)

Signature for BuildType in question:

public PolicyComplianceType getPolicyComplianceStatus();

Enum PolicyComplianceType:

  public enum PolicyComplianceType {
    CALCULATING("Calculating..."),
    NOT_ASSESSED("Not Assessed"),
    DID_NOT_PASS("Did Not Pass");
    ...
    ...
  }

What am I not seeing?

Upvotes: 2

Views: 3767

Answers (1)

John Bollinger
John Bollinger

Reputation: 180113

Supposing that that's a compiler error -- which it appears to be -- as opposed to a run-time error, I have to assume that you have two different types named PolicyComplianceType, in different packages, and that BuildType.getBuildInfo() returns a different one than is being imported in your test class. If that's not consistent with your current code, then possibly class BuildType is stale, and needs to be recompiled (it seems unlikely to be the test class that's stale). Along the same lines, perhaps the compiler is relying on an out of date version of class BuildType, even if the current source for that class is up to date.

Upvotes: 4

Related Questions