mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Add tests for equals, hashCode and toString
This commit is contained in:
@@ -26,9 +26,12 @@ import org.junit.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import nl.jqno.equalsverifier.*;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
||||
|
||||
public class CheckmarkListTest extends BaseUnitTest
|
||||
{
|
||||
@@ -351,4 +354,34 @@ public class CheckmarkListTest extends BaseUnitTest
|
||||
DateUtils.setFixedLocalTime(
|
||||
FIXED_LOCAL_TIME + days * Timestamp.DAY_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Timestamp t = Timestamp.ZERO.plus(100);
|
||||
Checkmark checkmark = new Checkmark(t, 2);
|
||||
String s = removePointers(checkmark.toString());
|
||||
assertThat(s, equalTo(
|
||||
"org.isoron.uhabits.core.models.Checkmark@00000000[" +
|
||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
||||
"value=2]"));
|
||||
|
||||
|
||||
CheckmarkList.Interval interval =
|
||||
new CheckmarkList.Interval(t, t.plus(1), t.plus(2));
|
||||
s = removePointers(interval.toString());
|
||||
assertThat(s, equalTo(
|
||||
"org.isoron.uhabits.core.models.CheckmarkList$Interval@00000000[" +
|
||||
"begin=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
||||
"center=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8726400000]," +
|
||||
"end=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8812800000]]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws Exception
|
||||
{
|
||||
EqualsVerifier.forClass(Checkmark.class).verify();
|
||||
EqualsVerifier.forClass(Timestamp.class).verify();
|
||||
EqualsVerifier.forClass(CheckmarkList.Interval.class).verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,11 @@ import org.isoron.uhabits.core.*;
|
||||
import org.junit.*;
|
||||
import org.junit.rules.*;
|
||||
|
||||
import nl.jqno.equalsverifier.*;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.*;
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class HabitTest extends BaseUnitTest
|
||||
@@ -126,4 +129,43 @@ public class HabitTest extends BaseUnitTest
|
||||
assertThat(h.getUriString(),
|
||||
equalTo("content://org.isoron.uhabits/habit/0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws Exception
|
||||
{
|
||||
EqualsVerifier
|
||||
.forClass(Habit.HabitData.class)
|
||||
.suppress(Warning.NONFINAL_FIELDS)
|
||||
.verify();
|
||||
|
||||
EqualsVerifier.forClass(Repetition.class).verify();
|
||||
EqualsVerifier.forClass(Score.class).verify();
|
||||
EqualsVerifier.forClass(Streak.class).verify();
|
||||
EqualsVerifier.forClass(Reminder.class).verify();
|
||||
EqualsVerifier.forClass(WeekdayList.class).verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Habit h = modelFactory.buildHabit();
|
||||
h.setReminder(new Reminder(22, 30, WeekdayList.EVERY_DAY));
|
||||
|
||||
String s = removePointers(h.toString());
|
||||
|
||||
String expected =
|
||||
"org.isoron.uhabits.core.models.Habit@00000000[" +
|
||||
"id=<null>," +
|
||||
"data=org.isoron.uhabits.core.models.Habit$HabitData@00000000[" +
|
||||
"name=,description=," +
|
||||
"frequency=org.isoron.uhabits.core.models.Frequency@00000000[numerator=3,denominator=7]," +
|
||||
"color=8,archived=false,targetType=0,targetValue=100.0,type=0,unit=," +
|
||||
"reminder=org.isoron.uhabits.core.models.Reminder@00000000[" +
|
||||
"hour=22,minute=30," +
|
||||
"days=org.isoron.uhabits.core.models.WeekdayList@00000000[" +
|
||||
"weekdays={true,true,true,true,true,true,true}]]," +
|
||||
"position=0]]";
|
||||
|
||||
assertThat(s, equalTo(expected));
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.util.*;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -186,4 +187,15 @@ public class RepetitionListTest extends BaseUnitTest
|
||||
verify(listener, times(2)).onModelChange();
|
||||
reset(listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 20);
|
||||
String s = removePointers(rep.toString());
|
||||
assertThat(s, equalTo(
|
||||
"org.isoron.uhabits.core.models.Repetition@00000000[" +
|
||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
||||
"value=20]"));
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@ import org.junit.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.hamcrest.number.IsCloseTo.*;
|
||||
|
||||
public class ScoreListTest extends BaseUnitTest
|
||||
|
||||
@@ -22,9 +22,12 @@ package org.isoron.uhabits.core.models;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.hamcrest.number.IsCloseTo.*;
|
||||
import static org.isoron.uhabits.core.models.Score.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.hamcrest.number.IsCloseTo.closeTo;
|
||||
import static org.isoron.uhabits.core.models.Score.compute;
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.removePointers;
|
||||
|
||||
|
||||
public class ScoreTest extends BaseUnitTest
|
||||
{
|
||||
@@ -66,4 +69,16 @@ public class ScoreTest extends BaseUnitTest
|
||||
assertThat(compute(freq, 0.5, check), closeTo(0.491192, E));
|
||||
assertThat(compute(freq, 0.75, check), closeTo(0.736788, E));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Score score = new Score(Timestamp.ZERO.plus(100), 150.0);
|
||||
String string = removePointers(score.toString());
|
||||
assertThat(string, equalTo(
|
||||
"org.isoron.uhabits.core.models.Score@00000000[" +
|
||||
"timestamp=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
||||
"value=150.0]"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,9 @@ import org.junit.*;
|
||||
import java.util.*;
|
||||
|
||||
import static junit.framework.TestCase.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.isoron.uhabits.core.utils.StringUtils.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class StreakListTest extends BaseUnitTest
|
||||
@@ -117,4 +118,16 @@ public class StreakListTest extends BaseUnitTest
|
||||
s = streaks.getNewestComputed();
|
||||
assertNull(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception
|
||||
{
|
||||
Timestamp time = Timestamp.ZERO.plus(100);
|
||||
Streak streak = new Streak(time, time.plus(10));
|
||||
String string = removePointers(streak.toString());
|
||||
assertThat(string, equalTo(
|
||||
"org.isoron.uhabits.core.models.Streak@00000000[" +
|
||||
"start=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=8640000000]," +
|
||||
"end=org.isoron.uhabits.core.models.Timestamp@00000000[unixTime=9504000000]]"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user