Add toString method to AbstractInstrument (#4883)

* Add toString method to AbstractInstrument

* add test for toString method

* use hasToString assertion for toString test
This commit is contained in:
Michal Korzeniewski 2022-10-25 20:24:48 +02:00 committed by GitHub
parent 45717e414f
commit 5ac1cef1e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -39,4 +39,9 @@ abstract class AbstractInstrument {
public int hashCode() {
return descriptor.hashCode();
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{" + "descriptor=" + getDescriptor() + '}';
}
}

View File

@ -22,6 +22,13 @@ class AbstractInstrumentTest {
assertThat(testInstrument.getDescriptor()).isSameAs(INSTRUMENT_DESCRIPTOR);
}
@Test
void testToString() {
TestInstrument testInstrument = new TestInstrument(INSTRUMENT_DESCRIPTOR);
assertThat(testInstrument)
.hasToString("TestInstrument{descriptor=" + INSTRUMENT_DESCRIPTOR + "}");
}
private static final class TestInstrument extends AbstractInstrument {
TestInstrument(InstrumentDescriptor descriptor) {
super(descriptor);