Skip to content

Commit b05a5b3

Browse files
kjcmatyb
authored andcommitted
Possible fix for Issue 79 - use of assertNotSame.
[Issue 79](matyb#79) questions the need for the `AboutAssertions.assertNotSameInstance` method, specifically the `aboutNotSame` assertion. This is my attempt to make both the positive assertion in `assertSameInstance` and the negative assertion more clear (if much longer) by making them more similar, and by giving each an example of how equality is different from "sameness". I'm still not sure it justifies the existence of `aboutNotSame`, which is used literally nowhere else.
1 parent 56e0361 commit b05a5b3

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎koans/src/beginner/AboutAssertions.java‎

100755100644
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,25 @@ public void assertEqualsWithDescriptiveMessage() {
6262

6363
@Koan
6464
public void assertSameInstance() {
65-
// Just because something is equal doesn't mean that it is the same.
66-
// It's only the same if the reference is the same.
67-
Object same = new Integer(1);
68-
Object sameReference = __;
69-
assertSame(same, sameReference);
65+
Integer original = new Integer(1);
66+
Integer same = original;
67+
Integer different = new Integer(1);
68+
// These are both equal to the original...
69+
assertEquals(original, same);
70+
assertEquals(original, different);
71+
// ...but only one refers to the same instance as the original.
72+
assertSame(original, __);
7073
}
7174

7275
@Koan
7376
public void assertNotSameInstance() {
74-
Integer same = new Integer(1);
75-
Integer sameReference = same;
76-
assertNotSame(same, sameReference);
77+
Integer original = new Integer(1);
78+
Integer same = original;
79+
Integer different = new Integer(1);
80+
// These are both equal to the original...
81+
assertEquals(original, same);
82+
assertEquals(original, different);
83+
// ...but only one of them refers to a different instance.
84+
assertNotSame(original, same); // We want equal, but _not_ the same.
7785
}
7886
}

0 commit comments

Comments
 (0)