@Override public String toString() { return "problem(" + getSource() + ": " + getMessage() + ")"; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ConfigProblem)) { return false; } ConfigProblem that = (ConfigProblem) o; return isError() == that.isError() && // Not perfect: the source can change, which changes the // equality. But this will do. As long as the source object // has correct equality / hashCode semantics, and it isn't used // as the key for a hash table when the source changes, this // will work. EqualUtil.isEqual(getSource(), that.getSource()) && getMessage().equals(that.getMessage()); }
@Test void getters_2() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Too bad", false); assertFalse(cp.isError()); assertEquals("Too bad", cp.getMessage()); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); part.withUsername("u"); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); }
@Test void getters_1() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Foo bar", true); assertEquals("Foo bar", cp.getMessage()); assertEquals(part, cp.getSource()); assertTrue(cp.isError()); assertEquals( "problem(" + part + ": Foo bar)", cp.toString()); }