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?

2 Answers 2

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?)

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.