Skip to content

Commit edfc26f

Browse files
author
David Reed
committed
Making AboutAssertions.assertSameInstance and AboutAssertions.assertNotSameInstance easier to understand
1 parent befebb1 commit edfc26f

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

koans/i18n/messages_en.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ beginner.AboutAssertions.assertBooleanFalse=Like the prior koan. Ponder if you w
66
beginner.AboutAssertions.assertNullObject=A keyword in java to represent an unitialized reference is 'null'. There are times when something should be null, and this assertion can prove that.
77
beginner.AboutAssertions.assertNotNullObject=Sometimes you merely wish to assert an object is not null. This assertion should be used sparingly, often a more specific assertion is appropriate.
88
beginner.AboutAssertions.assertEqualsWithDescriptiveMessage=Like the prior assertions, only this one invokes equals method on the 2nd to last argument, in this case, 1. This will blow up if the last two arguments are not .equal(...)
9-
beginner.AboutAssertions.assertSameInstance=An object may equal another object, but it will never be the same as another object. Two references to the same object is not the same as two references to two equal objects.
10-
beginner.AboutAssertions.assertNotSameInstance=Notice the same instance has been reassigned. Both same and sameReference refer to the same Integer instance. If sameReference were a new Object() of any type [hint!] this would pass.
9+
beginner.AboutAssertions.assertSameInstance=An object may equal another object, but it will never be the same as another object.
10+
beginner.AboutAssertions.assertNotSameInstance=Now we can see that two references to the same object is not the same as two references to two equal objects.
1111

1212
beginner.AboutObjects.objectEqualsNull=An Object instance should NEVER equal null keyword. This applies to all subclasses (everything except primitives subclass Object).
1313
beginner.AboutObjects.objectEqualsSelf=An Object instance should equal itself. This too applies to all subclasses of Object.

koans/src/beginner/AboutAssertions.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public void assertEqualsWithDescriptiveMessage() {
4444

4545
@Koan()
4646
public void assertSameInstance(){
47-
Integer same = new Integer(1);
48-
assertSame(same, __);
47+
Object same = new Integer(1);
48+
Object sameReference = __;
49+
assertSame(same, sameReference);
4950
}
5051

5152
@Koan()
5253
public void assertNotSameInstance(){
53-
Integer same = new Integer(1);
54-
Integer sameReference = same;
55-
assertNotSame(same, sameReference);
54+
Object same = new Integer(1);
55+
Object sameCopy = __;
56+
assertEquals(same, sameCopy);
57+
assertNotSame(same, sameCopy);
5658
}
5759
}

0 commit comments

Comments
 (0)