Skip to content

Commit 60d6ec3

Browse files
committed
[Issue-1] All unit tests should run from a reference point.
1 parent 02e3556 commit 60d6ec3

File tree

4 files changed

+118
-76
lines changed

4 files changed

+118
-76
lines changed

src/test/java/com/ginsberg/timestream/LocalDateStreamTest.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,84 +42,98 @@ public class LocalDateStreamTest {
4242
ChronoUnit.MONTHS, ChronoUnit.YEARS, ChronoUnit.DECADES, ChronoUnit.CENTURIES,
4343
ChronoUnit.ERAS, ChronoUnit.MILLENNIA);
4444

45+
final LocalDate now = LocalDate.now();
46+
4547
@Test
4648
public void stopsBeforeUntilDateGivenByChronoUnits() {
47-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
49+
final Stream<LocalDate> stream = LocalDateStream
50+
.from(now)
4851
.until(2, ChronoUnit.DAYS)
4952
.stream();
5053
assertThat(stream)
5154
.isNotNull()
52-
.containsExactly(LocalDate.now(), LocalDate.now().plusDays(1));
55+
.containsExactly(now, now.plusDays(1));
5356
}
5457

5558
@Test
5659
public void stopsBeforeUntilDateGivenByLocalDate() {
57-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
58-
.until(LocalDate.now().plusDays(2))
60+
final Stream<LocalDate> stream = LocalDateStream
61+
.from(now)
62+
.until(now.plusDays(2))
5963
.stream();
6064
assertThat(stream)
6165
.isNotNull()
62-
.containsExactly(LocalDate.now(), LocalDate.now().plusDays(1));
66+
.containsExactly(now, now.plusDays(1));
6367
}
6468

6569
@Test
6670
public void stopsOnToDateGivenByChronoUnits() {
67-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
71+
final Stream<LocalDate> stream = LocalDateStream
72+
.from(now)
6873
.to(2, ChronoUnit.DAYS)
6974
.stream();
7075
assertThat(stream)
7176
.isNotNull()
72-
.containsExactly(LocalDate.now(), LocalDate.now().plusDays(1), LocalDate.now().plusDays(2));
77+
.containsExactly(now, now.plusDays(1), now.plusDays(2));
7378
}
7479

7580
@Test
7681
public void stopsOnToDateGivenByLocalDate() {
77-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
78-
.to(LocalDate.now().plusDays(2))
82+
final Stream<LocalDate> stream = LocalDateStream
83+
.from(now)
84+
.to(now.plusDays(2))
7985
.stream();
8086
assertThat(stream)
8187
.isNotNull()
82-
.containsExactly(LocalDate.now(), LocalDate.now().plusDays(1), LocalDate.now().plusDays(2));
88+
.containsExactly(now, now.plusDays(1), now.plusDays(2));
8389
}
8490

8591
@Test
8692
public void stopsBeforeToWhenEveryIsAfterEndDate() {
87-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
93+
final Stream<LocalDate> stream = LocalDateStream
94+
.from(now)
8895
.to(3, ChronoUnit.DAYS)
8996
.every(2, ChronoUnit.DAYS)
9097
.stream();
9198
assertThat(stream)
9299
.isNotNull()
93-
.containsExactly(LocalDate.now(), LocalDate.now().plusDays(2));
100+
.containsExactly(now, now.plusDays(2));
94101
}
95102

96103
@Test
97104
public void identicalFromAndToCreateOnePointStream() {
98-
final Stream<LocalDate> stream = LocalDateStream.fromNow()
99-
.to(LocalDate.now())
105+
final Stream<LocalDate> stream = LocalDateStream
106+
.from(now)
107+
.to(now)
100108
.stream();
101109
assertThat(stream)
102110
.isNotNull()
103-
.containsExactly(LocalDate.now());
111+
.containsExactly(now);
104112
}
105113

106114
@Test
107115
public void noToDateRunsForever() {
108116
// No real way to test that a stream never ends so we will just make sure that this generates a lot of iterations.
109117
final int iterations = 1_000_000;
110-
final Stream<LocalDate> stream = LocalDateStream.fromNow().stream().limit(iterations);
118+
final Stream<LocalDate> stream = LocalDateStream
119+
.from(now)
120+
.stream()
121+
.limit(iterations);
111122
assertThat(stream)
112123
.isNotNull()
113-
.endsWith(LocalDate.now().plus(iterations-1, ChronoUnit.DAYS))
124+
.endsWith(now.plus(iterations-1, ChronoUnit.DAYS))
114125
.hasSize(iterations);
115126
}
116127

117128
@Test
118129
public void toBeforeFromRunsBackThroughTime() {
119-
final Stream<LocalDate> stream = LocalDateStream.fromNow().to(-2, ChronoUnit.DAYS).stream();
130+
final Stream<LocalDate> stream = LocalDateStream
131+
.from(now)
132+
.to(-2, ChronoUnit.DAYS)
133+
.stream();
120134
assertThat(stream)
121135
.isNotNull()
122-
.containsExactly(LocalDate.now(), LocalDate.now().minusDays(1), LocalDate.now().minusDays(2));
136+
.containsExactly(now, now.minusDays(1), now.minusDays(2));
123137
}
124138

125139
@Test(expected = NullPointerException.class)

src/test/java/com/ginsberg/timestream/LocalDateTimeStreamTest.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434

3535
public class LocalDateTimeStreamTest {
3636

37+
final LocalDateTime now = LocalDateTime.now();
38+
3739
@Test
3840
public void stopsBeforeUntilDateGivenByChronoUnits() {
39-
final LocalDateTime now = LocalDateTime.now();
40-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now)
41+
final Stream<LocalDateTime> stream = LocalDateTimeStream
42+
.from(now)
4143
.until(2, ChronoUnit.SECONDS)
4244
.stream();
4345
assertThat(stream)
@@ -47,9 +49,9 @@ public void stopsBeforeUntilDateGivenByChronoUnits() {
4749

4850
@Test
4951
public void stopsBeforeUntilDateGivenByLocalDateTime() {
50-
final LocalDateTime now = LocalDateTime.now();
51-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now)
52-
.until(LocalDateTime.now().plusSeconds(2))
52+
final Stream<LocalDateTime> stream = LocalDateTimeStream
53+
.from(now)
54+
.until(now.plusSeconds(2))
5355
.stream();
5456
assertThat(stream)
5557
.isNotNull()
@@ -58,8 +60,8 @@ public void stopsBeforeUntilDateGivenByLocalDateTime() {
5860

5961
@Test
6062
public void stopsOnToDateGivenByChronoUnits() {
61-
final LocalDateTime now = LocalDateTime.now();
62-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now)
63+
final Stream<LocalDateTime> stream = LocalDateTimeStream
64+
.from(now)
6365
.to(2, ChronoUnit.SECONDS)
6466
.stream();
6567
assertThat(stream)
@@ -69,9 +71,9 @@ public void stopsOnToDateGivenByChronoUnits() {
6971

7072
@Test
7173
public void stopsOnToDateGivenByLocalDateTime() {
72-
final LocalDateTime now = LocalDateTime.now();
73-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now)
74-
.to(LocalDateTime.now().plusSeconds(2))
74+
final Stream<LocalDateTime> stream = LocalDateTimeStream
75+
.from(now)
76+
.to(now.plusSeconds(2))
7577
.stream();
7678
assertThat(stream)
7779
.isNotNull()
@@ -80,8 +82,8 @@ public void stopsOnToDateGivenByLocalDateTime() {
8082

8183
@Test
8284
public void stopsBeforeToWhenEveryIsAfterEndDate() {
83-
final LocalDateTime now = LocalDateTime.now();
84-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now)
85+
final Stream<LocalDateTime> stream = LocalDateTimeStream
86+
.from(now)
8587
.to(3, ChronoUnit.SECONDS)
8688
.every(2, ChronoUnit.SECONDS)
8789
.stream();
@@ -92,20 +94,23 @@ public void stopsBeforeToWhenEveryIsAfterEndDate() {
9294

9395
@Test
9496
public void identicalFromAndToCreateOnePointStream() {
95-
final Stream<LocalDateTime> stream = LocalDateTimeStream.fromNow()
96-
.to(LocalDateTime.now())
97+
final Stream<LocalDateTime> stream = LocalDateTimeStream
98+
.from(now)
99+
.to(now)
97100
.stream();
98101
assertThat(stream)
99102
.isNotNull()
100-
.containsExactly(LocalDateTime.now());
103+
.containsExactly(now);
101104
}
102105

103106
@Test
104107
public void noToDateRunsForever() {
105108
// No real way to test that a stream never ends so we will just make sure that this generates a lot of iterations.
106109
final int iterations = 1_000_000;
107-
final LocalDateTime now = LocalDateTime.now();
108-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now).stream().limit(iterations);
110+
final Stream<LocalDateTime> stream = LocalDateTimeStream
111+
.from(now)
112+
.stream()
113+
.limit(iterations);
109114
assertThat(stream)
110115
.isNotNull()
111116
.endsWith(now.plus(iterations-1, ChronoUnit.SECONDS))
@@ -114,8 +119,10 @@ public void noToDateRunsForever() {
114119

115120
@Test
116121
public void toBeforeFromRunsBackThroughTime() {
117-
final LocalDateTime now = LocalDateTime.now();
118-
final Stream<LocalDateTime> stream = LocalDateTimeStream.from(now).to(-2, ChronoUnit.SECONDS).stream();
122+
final Stream<LocalDateTime> stream = LocalDateTimeStream
123+
.from(now)
124+
.to(-2, ChronoUnit.SECONDS)
125+
.stream();
119126
assertThat(stream)
120127
.isNotNull()
121128
.containsExactly(now, now.minusSeconds(1), now.minusSeconds(2));

src/test/java/com/ginsberg/timestream/YearMonthStreamTest.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,84 +41,98 @@ public class YearMonthStreamTest {
4141
private final Set<ChronoUnit> validChronoUnits = Sets.newLinkedHashSet(ChronoUnit.MONTHS, ChronoUnit.YEARS,
4242
ChronoUnit.DECADES, ChronoUnit.CENTURIES, ChronoUnit.ERAS, ChronoUnit.MILLENNIA);
4343

44+
final YearMonth now = YearMonth.now();
45+
4446
@Test
4547
public void stopsBeforeUntilDateGivenByChronoUnits() {
46-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
48+
final Stream<YearMonth> stream = YearMonthStream
49+
.from(now)
4750
.until(2, ChronoUnit.MONTHS)
4851
.stream();
4952
assertThat(stream)
5053
.isNotNull()
51-
.containsExactly(YearMonth.now(), YearMonth.now().plusMonths(1));
54+
.containsExactly(now, now.plusMonths(1));
5255
}
5356

5457
@Test
5558
public void stopsBeforeUntilDateGivenByYearMonth() {
56-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
57-
.until(YearMonth.now().plusMonths(2))
59+
final Stream<YearMonth> stream = YearMonthStream
60+
.from(now)
61+
.until(now.plusMonths(2))
5862
.stream();
5963
assertThat(stream)
6064
.isNotNull()
61-
.containsExactly(YearMonth.now(), YearMonth.now().plusMonths(1));
65+
.containsExactly(now, now.plusMonths(1));
6266
}
6367

6468
@Test
6569
public void stopsOnToDateGivenByChronoUnits() {
66-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
70+
final Stream<YearMonth> stream = YearMonthStream
71+
.from(now)
6772
.to(2, ChronoUnit.MONTHS)
6873
.stream();
6974
assertThat(stream)
7075
.isNotNull()
71-
.containsExactly(YearMonth.now(), YearMonth.now().plusMonths(1), YearMonth.now().plusMonths(2));
76+
.containsExactly(now, now.plusMonths(1), now.plusMonths(2));
7277
}
7378

7479
@Test
7580
public void stopsOnToDateGivenByYearMonth() {
76-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
77-
.to(YearMonth.now().plusMonths(2))
81+
final Stream<YearMonth> stream = YearMonthStream
82+
.from(now)
83+
.to(now.plusMonths(2))
7884
.stream();
7985
assertThat(stream)
8086
.isNotNull()
81-
.containsExactly(YearMonth.now(), YearMonth.now().plusMonths(1), YearMonth.now().plusMonths(2));
87+
.containsExactly(now, now.plusMonths(1), now.plusMonths(2));
8288
}
8389

8490
@Test
8591
public void stopsBeforeToWhenEveryIsAfterEndDate() {
86-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
92+
final Stream<YearMonth> stream = YearMonthStream
93+
.from(now)
8794
.to(3, ChronoUnit.MONTHS)
8895
.every(2, ChronoUnit.MONTHS)
8996
.stream();
9097
assertThat(stream)
9198
.isNotNull()
92-
.containsExactly(YearMonth.now(), YearMonth.now().plusMonths(2));
99+
.containsExactly(now, now.plusMonths(2));
93100
}
94101

95102
@Test
96103
public void identicalFromAndToCreateOnePointStream() {
97-
final Stream<YearMonth> stream = YearMonthStream.fromNow()
98-
.to(YearMonth.now())
104+
final Stream<YearMonth> stream = YearMonthStream
105+
.from(now)
106+
.to(now)
99107
.stream();
100108
assertThat(stream)
101109
.isNotNull()
102-
.containsExactly(YearMonth.now());
110+
.containsExactly(now);
103111
}
104112

105113
@Test
106114
public void noToDateRunsForever() {
107115
// No real way to test that a stream never ends so we will just make sure that this generates a lot of iterations.
108116
final int iterations = 1_000_000;
109-
final Stream<YearMonth> stream = YearMonthStream.fromNow().stream().limit(iterations);
117+
final Stream<YearMonth> stream = YearMonthStream
118+
.from(now)
119+
.stream()
120+
.limit(iterations);
110121
assertThat(stream)
111122
.isNotNull()
112-
.endsWith(YearMonth.now().plus(iterations-1, ChronoUnit.MONTHS))
123+
.endsWith(now.plus(iterations-1, ChronoUnit.MONTHS))
113124
.hasSize(iterations);
114125
}
115126

116127
@Test
117128
public void toBeforeFromRunsBackThroughTime() {
118-
final Stream<YearMonth> stream = YearMonthStream.fromNow().to(-2, ChronoUnit.MONTHS).stream();
129+
final Stream<YearMonth> stream = YearMonthStream
130+
.from(now)
131+
.to(-2, ChronoUnit.MONTHS)
132+
.stream();
119133
assertThat(stream)
120134
.isNotNull()
121-
.containsExactly(YearMonth.now(), YearMonth.now().minusMonths(1), YearMonth.now().minusMonths(2));
135+
.containsExactly(now, now.minusMonths(1), now.minusMonths(2));
122136
}
123137

124138
@Test(expected = NullPointerException.class)

0 commit comments

Comments
 (0)