From edfc26fefee751ff300e804e70a06499ed70c820 Mon Sep 17 00:00:00 2001 From: David Reed Date: Fri, 17 Aug 2012 19:19:17 +0200 Subject: [PATCH] Making AboutAssertions.assertSameInstance and AboutAssertions.assertNotSameInstance easier to understand --- koans/i18n/messages_en.properties | 4 ++-- koans/src/beginner/AboutAssertions.java | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/koans/i18n/messages_en.properties b/koans/i18n/messages_en.properties index 4fbd27e5..327333aa 100644 --- a/koans/i18n/messages_en.properties +++ b/koans/i18n/messages_en.properties @@ -6,8 +6,8 @@ beginner.AboutAssertions.assertBooleanFalse=Like the prior koan. Ponder if you w 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. 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. 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(...) -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. -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. +beginner.AboutAssertions.assertSameInstance=An object may equal another object, but it will never be the same as another object. +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. beginner.AboutObjects.objectEqualsNull=An Object instance should NEVER equal null keyword. This applies to all subclasses (everything except primitives subclass Object). beginner.AboutObjects.objectEqualsSelf=An Object instance should equal itself. This too applies to all subclasses of Object. diff --git a/koans/src/beginner/AboutAssertions.java b/koans/src/beginner/AboutAssertions.java index 3f27ed19..d06519fb 100755 --- a/koans/src/beginner/AboutAssertions.java +++ b/koans/src/beginner/AboutAssertions.java @@ -44,14 +44,16 @@ public void assertEqualsWithDescriptiveMessage() { @Koan() public void assertSameInstance(){ - Integer same = new Integer(1); - assertSame(same, __); + Object same = new Integer(1); + Object sameReference = __; + assertSame(same, sameReference); } @Koan() public void assertNotSameInstance(){ - Integer same = new Integer(1); - Integer sameReference = same; - assertNotSame(same, sameReference); + Object same = new Integer(1); + Object sameCopy = __; + assertEquals(same, sameCopy); + assertNotSame(same, sameCopy); } }