Skip to content

Commit f656d75

Browse files
HeikoKlarejukzi
authored andcommitted
Fix FinalTip#hashcode() and TipProviderTest#testGetNextTip() #1148
The test case org.eclipse.tips.core.TipProviderTest#testGetNextTip() randomly fails because it checks that the read state of a tip after being set can properly be retrieved. This functionality relies on the hash code of tips staying the same, but the one for the FinalTip currently changes if the system time has changed, as it re-calculates the creation time used for the calculation of the hash code on every access. With this change, the creation time for the FinalTip is stored such that its hash code does not change. This also fixes the according test case. Fixes #1148
1 parent d2ed9d5 commit f656d75

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

ua/org.eclipse.tips.core/src/org/eclipse/tips/core/internal/FinalTip.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ public class FinalTip extends Tip implements IHtmlTip {
3131
private static final String EH1 = "</h1>"; //$NON-NLS-1$
3232
private static final String H1 = "<h1>"; //$NON-NLS-1$
3333

34-
/**
35-
* Constructor.
36-
*/
34+
private final Date creationDate;
35+
3736
public FinalTip(String providerId) {
3837
super(providerId);
38+
this.creationDate = Calendar.getInstance().getTime();
3939
}
4040

4141
@Override
4242
public Date getCreationDate() {
43-
Calendar instance = Calendar.getInstance();
44-
return instance.getTime();
43+
return creationDate;
4544
}
4645

4746
@Override

ua/org.eclipse.tips.tests/src/org/eclipse/tips/core/TipProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void testGetCurrentTip2() {
9696
@Test
9797
public void testGetNextTip() {
9898
createTestData();
99+
assertEquals(fProvider.getCurrentTip(), fProvider.getNextTip());
99100
fManager.setAsRead(fProvider.getNextTip());
100101
assertNotEquals(fProvider.getCurrentTip(), fProvider.getNextTip());
101102
Tip nextTip = fProvider.getNextTip();

0 commit comments

Comments
 (0)