Skip to content

Commit

Permalink
Making AboutAssertions.assertSameInstance and AboutAssertions.assertN…
Browse files Browse the repository at this point in the history
…otSameInstance easier to understand
  • Loading branch information
David Reed committed Aug 17, 2012
1 parent befebb1 commit edfc26f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions koans/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions koans/src/beginner/AboutAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit edfc26f

Please sign in to comment.