1

I'm trying to make a test-case to check for the Dropwizard Metric Meter name: Here's the code:

@Test
public void getMeterName(){
  String metricsPrefix = "com.company.team";
  String tagSupplied = "tenant.db.table";
  String expectedMeterName = "com.company.team.tenant.db.table";

  assertSame(expectedMeterName,MetricRegistry.name(metricsPrefix,tagSupplied));
}

This is the error I'm getting:

java.lang.AssertionError: expected same:<com.company.team.tenant.db.table> was not:<com.company.team.tenant.db.table>
Expected :com.company.team.tenant.db.table
Actual   :com.company.team.tenant.db.table

What am I missing here?

Satyam Raj
  • 61
  • 1
  • 11

2 Answers2

5

What am I missing here?

The strings that you are testing are equal but not the same object.

You are using assertSame where you should be using assertEquals.

This is analogous to the mistake of using == to compare strings.

(See also: How do I compare strings in Java?)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Use assertEquals() instead of assertSame() because you can't use assertSame() with Strings. .Refer this JUnit asserting two Strings whether they're equal or not

Hasindu Dahanayake
  • 1,344
  • 2
  • 14
  • 37