Skip to content

Commit de225ff

Browse files
committed
Release 3.10.4 2022-10-13: Dependency bumps and better tests (most changes from Aug 13)
- Fixed a typo in an exception message. - Changed two unit tests from older jUnit to jUnit 5 Jupiter. - Removed the Deprecated annotation from the .equals() and .hashcode() methods of the Option classes (Some and None). I don't think they prevented any misuse and I ended up suppressing the warnings where Paguro used those methods. Basically, they are no more dangerous than most Java .equals() methods.
1 parent 1d59c21 commit de225ff

File tree

11 files changed

+86
-57
lines changed

11 files changed

+86
-57
lines changed

CHANGE_LOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ tells you what to use instead. Once we delete the deprecated methods, that docu
77

88
// CONSIDER public interface UnmodMap<K,V> extends Map<K,V>, UnmodIterable<UnmodMap.UnEntry<K,V>>, Sized {
99
// CONSIDER Changing to Map.Entry
10+
11+
## Release 3.10.4 2022-10-13: Dependency bumps and better tests (most changes from Aug 13)
12+
- Fixed a typo in an exception message.
13+
- Changed two unit tests from older jUnit to jUnit 5 Jupiter.
14+
- Removed the Deprecated annotation from the .equals() and .hashcode() methods of the Option classes (Some and None).
15+
I don't think they prevented any misuse and I ended up suppressing the warnings where Paguro used those methods.
16+
Basically, they are no more dangerous than most Java .equals() methods.
17+
1018
## Release 3.10.3 2022-05-08: concat() and precat()
1119
- Implemented concat() and precat() methods on RrbTree and precat() on ImRrbTree and MutRrbTree
1220
because:

Paguro.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</content>
1111
<orderEntry type="inheritedJdk" />
1212
<orderEntry type="sourceFolder" forTests="false" />
13-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
13+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.9.0" level="project" />
1414
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
15-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
15+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.9.0" level="project" />
1616
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
1717
<orderEntry type="library" name="Maven: org.jetbrains:annotations:23.0.0" level="project" />
1818
<orderEntry type="library" scope="TEST" name="Maven: org.organicdesign:TestUtils:1.0.6" level="project" />

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
3838
-->
3939
<groupId>org.organicdesign</groupId>
4040
<artifactId>Paguro</artifactId>
41-
<version>3.10.3</version>
41+
<version>3.10.4</version>
4242
<packaging>jar</packaging>
4343

4444
<name>Paguro</name>
@@ -77,7 +77,7 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
7777
<plugin>
7878
<groupId>org.apache.maven.plugins</groupId>
7979
<artifactId>maven-enforcer-plugin</artifactId>
80-
<version>3.0.0</version>
80+
<version>3.1.0</version>
8181
<executions>
8282
<execution>
8383
<id>enforce-maven</id>
@@ -129,7 +129,7 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
129129
<groupId>org.apache.maven.plugins</groupId>
130130
<artifactId>maven-javadoc-plugin</artifactId>
131131
<!-- JavaDoc wasn't providing the right links to the Java APIs with the default version of the plugin on my machine. -->
132-
<version>3.4.0</version>
132+
<version>3.4.1</version>
133133
<configuration>
134134
<additionalOptions>-Xdoclint:none</additionalOptions>
135135
</configuration>
@@ -178,7 +178,7 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
178178
<dependency>
179179
<groupId>org.junit.jupiter</groupId>
180180
<artifactId>junit-jupiter-api</artifactId>
181-
<version>5.8.2</version>
181+
<version>5.9.0</version>
182182
<scope>test</scope>
183183
</dependency>
184184
<dependency>

src/main/java/org/organicdesign/fp/oneOf/None.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ private None() {}
4141
/** {@inheritDoc} */
4242
@Override public <U> Option<U> then(Fn1<T,Option<U>> f) { return Option.none(); }
4343

44-
/** Valid, but deprecated because it's usually an error to call this in client code. */
45-
@Deprecated // Has no effect. Darn!
44+
/** This final singleton class always returns zero (it represents None after all). */
4645
@Override public int hashCode() { return 0; }
4746

48-
/** Valid, but deprecated because it's usually an error to call this in client code. */
49-
@Deprecated // Has no effect. Darn!
47+
/** Asks if the other object is instanceof the final singleton class None */
5048
@Override public boolean equals(Object other) {
5149
return other instanceof org.organicdesign.fp.oneOf.None;
5250
}

src/main/java/org/organicdesign/fp/oneOf/OneOf2.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ protected OneOf2(
107107
throw new IllegalArgumentException("Selected item index must be 0-1");
108108
}
109109
if (!types.get(index).isInstance(o)) {
110-
throw new ClassCastException("You specified index " + index + ", indicating a(n) " +
110+
// Made this "indicating a " instead of "indicating a(n) " because a(n) looks like a function.
111+
// Poor grammar, in this case, is less confusing.
112+
throw new ClassCastException("You specified index " + index + ", indicating a " +
111113
types.get(index).getCanonicalName() + "," +
112114
" but passed a " + o.getClass().getCanonicalName());
113115
}

src/main/java/org/organicdesign/fp/oneOf/OneOf3.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected OneOf3(
4141
throw new IllegalArgumentException("Selected item index must be 0-2");
4242
}
4343
if (!types.get(index).isInstance(o)) {
44-
throw new ClassCastException("You specified index " + index + ", indicating a(n) " +
44+
throw new ClassCastException("You specified index " + index + ", indicating a " +
4545
types.get(index).getCanonicalName() + "," +
4646
" but passed a " + o.getClass().getCanonicalName());
4747
}

src/main/java/org/organicdesign/fp/oneOf/OneOf4.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected OneOf4(
4343
throw new IllegalArgumentException("Selected item index must be 0-3");
4444
}
4545
if (!types.get(index).isInstance(o)) {
46-
throw new ClassCastException("You specified index " + index + ", indicating a(n) " +
46+
throw new ClassCastException("You specified index " + index + ", indicating a " +
4747
types.get(index).getCanonicalName() + "," +
4848
" but passed a " + o.getClass().getCanonicalName());
4949
}

src/main/java/org/organicdesign/fp/oneOf/OneOf5.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected OneOf5(
4545
throw new IllegalArgumentException("Selected item index must be 0-4");
4646
}
4747
if (!types.get(index).isInstance(o)) {
48-
throw new ClassCastException("You specified index " + index + ", indicating a(n) " +
48+
throw new ClassCastException("You specified index " + index + ", indicating a " +
4949
types.get(index).getCanonicalName() + "," +
5050
" but passed a " + o.getClass().getCanonicalName());
5151
}

src/main/java/org/organicdesign/fp/oneOf/Option.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ together, failing fast at the first none() or continuing through as many operati
6161
@SuppressWarnings("unchecked")
6262
static <T> @NotNull Option<T> none() { return None.NONE; }
6363

64-
/** Public static factory method for constructing the Some Option. */
64+
/** Public static factory method for constructing the {@link Some} Option. */
6565
static <T> @NotNull Option<T> some(T t) {
6666
return new Some<>(t);
6767
}
6868

6969
/** Construct an option, but if t is null, make it None instead of Some. */
70+
@SuppressWarnings({"deprecation", "RedundantSuppression"})
7071
static <T> @NotNull Option<T> someOrNullNoneOf(@Nullable T t) {
7172
if ( (t == null) || None.NONE.equals(t) ) {
7273
return none();

src/test/java/org/organicdesign/fp/oneOf/OneOf2OrNoneTest.java

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.organicdesign.fp.oneOf;
22

33
import org.jetbrains.annotations.NotNull;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55
import org.organicdesign.testUtils.EqualsContract;
66

7-
import static org.junit.Assert.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
89
import static org.organicdesign.fp.oneOf.Option.none;
910
import static org.organicdesign.testUtils.Serialization.serializeDeserialize;
1011

@@ -20,7 +21,8 @@ static class Str_Int extends OneOf2<String,Integer> {
2021
static Option<Str_Int> ofNone() { return Option.none(); }
2122
}
2223

23-
@Test public void testBasics() {
24+
@Test
25+
public void testBasics() {
2426
Option<Str_Int> si = Str_Int.of(57);
2527
assertEquals(Integer.valueOf(57), si.match(some -> some.match(x -> -99,
2628
y -> y),
@@ -42,7 +44,9 @@ static class Str_Int extends OneOf2<String,Integer> {
4244
assertEquals(None.NONE, serializeDeserialize(none()));
4345
}
4446

45-
@Test public void testEquality() {
47+
@SuppressWarnings({"deprecation", "RedundantSuppression"})
48+
@Test
49+
public void testEquality() {
4650
assertEquals(0, Str_Int.of("").hashCode());
4751
assertEquals(1, Str_Int.of(0).hashCode());
4852
assertEquals(none().hashCode(), Str_Int.ofNone().hashCode());
@@ -56,24 +60,36 @@ static class Str_Int extends OneOf2<String,Integer> {
5660
Str_Int.of(-97));
5761
}
5862

59-
@Test(expected = IllegalArgumentException.class)
60-
public void subClassExa_n() { new Str_Int("hi", -1); }
63+
@Test
64+
public void subClassExceptions() {
65+
Exception e;
6166

62-
@Test(expected = IllegalArgumentException.class)
63-
public void subClassEx_bn() { new Str_Int(1, -1); }
67+
e = assertThrowsExactly(IllegalArgumentException.class,
68+
() -> new Str_Int("hi", -1));
69+
assertEquals("Selected item index must be 0-1", e.getMessage());
6470

65-
@Test(expected = ClassCastException.class)
66-
public void subClassExab_0() { new Str_Int(1, 0); }
71+
e = assertThrowsExactly(IllegalArgumentException.class,
72+
() -> new Str_Int(1, -1));
73+
assertEquals("Selected item index must be 0-1", e.getMessage());
6774

68-
@Test(expected = ClassCastException.class)
69-
public void subClassExa_1() { new Str_Int("hi", 1); }
75+
e = assertThrowsExactly(ClassCastException.class,
76+
() -> new Str_Int(1, 0));
77+
assertEquals("You specified index 0, indicating a java.lang.String, but passed a java.lang.Integer", e.getMessage());
7078

71-
@Test(expected = IllegalArgumentException.class)
72-
public void subClassExa_2() { new Str_Int("hi", 2); }
79+
e = assertThrowsExactly(ClassCastException.class,
80+
() -> new Str_Int("hi", 1));
81+
assertEquals("You specified index 1, indicating a java.lang.Integer, but passed a java.lang.String", e.getMessage());
7382

74-
@Test(expected = IllegalArgumentException.class)
75-
public void subClassEx_b2() { new Str_Int(1, 2); }
83+
e = assertThrowsExactly(IllegalArgumentException.class,
84+
() -> new Str_Int("hi", 2));
85+
assertEquals("Selected item index must be 0-1", e.getMessage());
7686

77-
@Test(expected = IllegalArgumentException.class)
78-
public void subClassEx_b3() { new Str_Int(1, 3); }
87+
e = assertThrowsExactly(IllegalArgumentException.class,
88+
() -> new Str_Int(1, 2));
89+
assertEquals("Selected item index must be 0-1", e.getMessage());
90+
91+
e = assertThrowsExactly(IllegalArgumentException.class,
92+
() -> new Str_Int(1, 3));
93+
assertEquals("Selected item index must be 0-1", e.getMessage());
94+
}
7995
}

src/test/java/org/organicdesign/fp/oneOf/OptionTest.java

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package org.organicdesign.fp.oneOf;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

5-
import static org.junit.Assert.*;
5+
import static org.junit.jupiter.api.Assertions.*;
66
import static org.organicdesign.fp.TestUtilities.serializeDeserialize;
77
import static org.organicdesign.testUtils.EqualsContract.equalsDistinctHashCode;
88

99
public class OptionTest {
1010

11-
@Test public void basics() {
11+
@Test
12+
public void basics() {
1213
Option<Integer> o1a = Option.some(1);
1314
assertTrue(o1a.isSome());
1415
assertEquals(Integer.valueOf(1), o1a.get());
@@ -43,18 +44,21 @@ public class OptionTest {
4344
() -> 2));
4445
assertEquals(None.NONE, Option.someOrNullNoneOf(None.NONE));
4546

46-
//noinspection SimplifiableJUnitAssertion,EqualsWithItself
47-
assertTrue(None.NONE.equals(None.NONE));
48-
//noinspection SimplifiableJUnitAssertion
49-
assertTrue(None.NONE.equals(Option.someOrNullNoneOf(null)));
47+
assertEquals(None.NONE, None.NONE);
48+
assertEquals(None.NONE, Option.someOrNullNoneOf(null));
5049
}
5150

52-
@Test(expected = IllegalStateException.class) public void noneEx() {
53-
Option.none().get();
54-
}
51+
@Test
52+
public void testExceptions() {
53+
IllegalStateException iSE;
54+
iSE = assertThrowsExactly(IllegalStateException.class,
55+
() -> Option.none().get());
56+
assertEquals("Called get on None", iSE.getMessage());
57+
58+
iSE = assertThrowsExactly(IllegalStateException.class,
59+
() -> Option.someOrNullNoneOf(null).get());
5560

56-
@Test(expected = IllegalStateException.class) public void nullNoneEx() {
57-
Option.someOrNullNoneOf(null).get();
61+
assertEquals("Called get on None", iSE.getMessage());
5862
}
5963
//
6064
// @Test public void iterationTest() {
@@ -105,17 +109,17 @@ public class OptionTest {
105109
Option<Integer> z = Option.some(null);
106110
Option<Integer> n1 = Option.none();
107111
Option<Integer> n2 = Option.someOrNullNoneOf(null);
108-
Option n3 = Option.none();
112+
Option<Integer> n3 = Option.none();
109113

110-
assertTrue(n1 == n2);
111-
assertTrue(n2 == n3);
114+
assertSame(n1, n2);
115+
assertSame(n2, n3);
112116

113-
assertFalse(n1.equals(z));
114-
assertFalse(z.equals(n1));
115-
assertFalse(n2.equals(z));
116-
assertFalse(z.equals(n2));
117-
assertFalse(n3.equals(z));
118-
assertFalse(z.equals(n3));
117+
assertNotEquals(n1, z);
118+
assertNotEquals(z, n1);
119+
assertNotEquals(n2, z);
120+
assertNotEquals(z, n2);
121+
assertNotEquals(n3, z);
122+
assertNotEquals(z, n3);
119123

120124
assertNotEquals(z.hashCode(), n1.hashCode());
121125
assertNotEquals(z.hashCode(), n2.hashCode());
@@ -124,15 +128,15 @@ public class OptionTest {
124128
assertEquals(n1.hashCode(), n2.hashCode());
125129
assertEquals(n2.hashCode(), n3.hashCode());
126130

127-
assertTrue(n1.equals(n2));
128-
assertTrue(n2.equals(n1));
131+
assertEquals(n1, n2);
132+
assertEquals(n2, n1);
129133

130134
equalsDistinctHashCode(o1a, o1b, o1c, n1);
131135

132136
equalsDistinctHashCode(Option.some(null), Option.some(null), Option.some(null), n2);
133137

134138
// None is a serializable singleton.
135-
assertTrue(n1 == serializeDeserialize(n1));
139+
assertSame(n1, serializeDeserialize(n1));
136140
assertEquals(n1, serializeDeserialize(n1));
137141
}
138142

0 commit comments

Comments
 (0)