๐Ÿ“ฆ Abbondanzo / Journey

๐Ÿ“„ entry_test.dart ยท 141 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141import 'package:journey/entries/entries.dart';
import 'package:test/test.dart';

void main() {
  group('Entry', () {
    group('hashCode', () {
      test('if two equal entries, return the same hashCode', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1.hashCode, equals(entry2.hashCode));
      });

      test('if two entries with different values, return different hashCode',
          () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id1',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'id2',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1.hashCode, isNot(equals(entry2.hashCode)));
      });

      test('if two entries with inverted values, return the same hashCode', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'title',
            title: 'id',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1.hashCode, (equals(entry2.hashCode)));
      });
    });

    group('==', () {
      test('if two equal entries, returns true', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1 == entry2, isTrue);
        expect(entry2 == entry1, isTrue);
      });

      test('if two entries with different values, return false', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id1',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'id2',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1 == entry2, isFalse);
        expect(entry2 == entry1, isFalse);
      });

      test('if two entries with inverted values, return false', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime.now();
        final entry1 = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final entry2 = Entry(
            id: 'title',
            title: 'id',
            body: 'body',
            dateTime: dateTime,
            location: location);
        expect(entry1 == entry2, isFalse);
        expect(entry2 == entry1, isFalse);
      });
    });

    group('toString', () {
      test('returns string with all values', () {
        final location = Location('city', 'country', LatLng(1, 2));
        final dateTime = DateTime(2021, 5, 21, 6);
        final entry = Entry(
            id: 'id',
            title: 'title',
            body: 'body',
            dateTime: dateTime,
            location: location);
        final expectedString = 'Entry{id: id, title: title, body: body, '
            'dateTime: 2021-05-21 06:00:00.000, '
            'location: Location{city: city, country: country, '
            'latLng: LatLng{latitude: 1.0, longitude: 2.0}}}';
        expect(entry.toString(), equals(expectedString));
      });
    });
  });
}