diff --git a/javaslang-gwt/src/test/java/client/GwtTestCollections.java b/javaslang-gwt/src/test/java/client/GwtTestCollections.java index 941df2a87b..e02e1b538a 100644 --- a/javaslang-gwt/src/test/java/client/GwtTestCollections.java +++ b/javaslang-gwt/src/test/java/client/GwtTestCollections.java @@ -15,6 +15,7 @@ public String getModuleName() { public void testTuple() { Tuple1 t = Tuple.of(1); + assertEquals((int) t._1, 1); assertEquals((int) t._1(), 1); } diff --git a/javaslang/generator/Generator.scala b/javaslang/generator/Generator.scala index bd517e61ea..30654ff38d 100644 --- a/javaslang/generator/Generator.scala +++ b/javaslang/generator/Generator.scala @@ -1906,7 +1906,7 @@ def generateTestClasses(): Unit = { @$test public void shouldReturnElements() { final Tuple$i$intGenerics tuple = createIntTuple(${(1 to i).gen(j => s"$j") mkString ", "}); - ${(1 to i).gen(j => s"$assertThat(tuple._$j()).isEqualTo($j);\n")} + ${(1 to i).gen(j => s"$assertThat(tuple._$j).isEqualTo($j);\n")} } """)} @@ -1915,7 +1915,7 @@ def generateTestClasses(): Unit = { @$test public void shouldUpdate$j() { final Tuple$i$intGenerics tuple = createIntTuple(${(1 to i).gen(j => s"$j") mkString ", "}).update$j(42); - ${(1 to i).gen(k => s"$assertThat(tuple._$k()).isEqualTo(${if (j == k) 42 else k});\n")} + ${(1 to i).gen(k => s"$assertThat(tuple._$k).isEqualTo(${if (j == k) 42 else k});\n")} } """)("\n\n")} diff --git a/javaslang/src-gen/test/java/javaslang/Tuple1Test.java b/javaslang/src-gen/test/java/javaslang/Tuple1Test.java index 5105c8be33..d2d905112f 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple1Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple1Test.java @@ -34,13 +34,13 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple1 tuple = createIntTuple(1); - assertThat(tuple._1()).isEqualTo(1); + assertThat(tuple._1).isEqualTo(1); } @Test public void shouldUpdate1() { final Tuple1 tuple = createIntTuple(1).update1(42); - assertThat(tuple._1()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple2Test.java b/javaslang/src-gen/test/java/javaslang/Tuple2Test.java index 15cdcb59eb..15ba1f9b72 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple2Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple2Test.java @@ -36,22 +36,22 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple2 tuple = createIntTuple(1, 2); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); } @Test public void shouldUpdate1() { final Tuple2 tuple = createIntTuple(1, 2).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); } @Test public void shouldUpdate2() { final Tuple2 tuple = createIntTuple(1, 2).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple3Test.java b/javaslang/src-gen/test/java/javaslang/Tuple3Test.java index e788f6d4a0..4aa2e12c06 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple3Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple3Test.java @@ -34,33 +34,33 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple3 tuple = createIntTuple(1, 2, 3); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); } @Test public void shouldUpdate1() { final Tuple3 tuple = createIntTuple(1, 2, 3).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); } @Test public void shouldUpdate2() { final Tuple3 tuple = createIntTuple(1, 2, 3).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); } @Test public void shouldUpdate3() { final Tuple3 tuple = createIntTuple(1, 2, 3).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple4Test.java b/javaslang/src-gen/test/java/javaslang/Tuple4Test.java index 92b4af0382..68054c8647 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple4Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple4Test.java @@ -34,46 +34,46 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple4 tuple = createIntTuple(1, 2, 3, 4); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); } @Test public void shouldUpdate1() { final Tuple4 tuple = createIntTuple(1, 2, 3, 4).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); } @Test public void shouldUpdate2() { final Tuple4 tuple = createIntTuple(1, 2, 3, 4).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); } @Test public void shouldUpdate3() { final Tuple4 tuple = createIntTuple(1, 2, 3, 4).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); - assertThat(tuple._4()).isEqualTo(4); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); + assertThat(tuple._4).isEqualTo(4); } @Test public void shouldUpdate4() { final Tuple4 tuple = createIntTuple(1, 2, 3, 4).update4(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple5Test.java b/javaslang/src-gen/test/java/javaslang/Tuple5Test.java index e045d3f828..c32949170f 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple5Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple5Test.java @@ -34,61 +34,61 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); } @Test public void shouldUpdate1() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); } @Test public void shouldUpdate2() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); } @Test public void shouldUpdate3() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); } @Test public void shouldUpdate4() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5).update4(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(42); - assertThat(tuple._5()).isEqualTo(5); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(42); + assertThat(tuple._5).isEqualTo(5); } @Test public void shouldUpdate5() { final Tuple5 tuple = createIntTuple(1, 2, 3, 4, 5).update5(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple6Test.java b/javaslang/src-gen/test/java/javaslang/Tuple6Test.java index d0184de86e..8928066594 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple6Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple6Test.java @@ -34,78 +34,78 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate1() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate2() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate3() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate4() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update4(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(42); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(42); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate5() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update5(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(42); - assertThat(tuple._6()).isEqualTo(6); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(42); + assertThat(tuple._6).isEqualTo(6); } @Test public void shouldUpdate6() { final Tuple6 tuple = createIntTuple(1, 2, 3, 4, 5, 6).update6(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple7Test.java b/javaslang/src-gen/test/java/javaslang/Tuple7Test.java index a397c0b29c..8b41a9196f 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple7Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple7Test.java @@ -34,97 +34,97 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate1() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate2() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate3() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate4() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update4(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(42); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(42); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate5() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update5(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(42); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(42); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate6() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update6(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(42); - assertThat(tuple._7()).isEqualTo(7); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(42); + assertThat(tuple._7).isEqualTo(7); } @Test public void shouldUpdate7() { final Tuple7 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7).update7(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(42); } @Test diff --git a/javaslang/src-gen/test/java/javaslang/Tuple8Test.java b/javaslang/src-gen/test/java/javaslang/Tuple8Test.java index c1f95b47f7..d9cb4a660b 100644 --- a/javaslang/src-gen/test/java/javaslang/Tuple8Test.java +++ b/javaslang/src-gen/test/java/javaslang/Tuple8Test.java @@ -34,118 +34,118 @@ public void shouldGetArity() { @Test public void shouldReturnElements() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate1() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update1(42); - assertThat(tuple._1()).isEqualTo(42); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(42); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate2() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update2(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(42); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(42); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate3() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update3(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(42); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(42); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate4() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update4(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(42); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(42); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate5() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update5(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(42); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(42); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate6() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update6(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(42); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(42); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate7() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update7(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(42); - assertThat(tuple._8()).isEqualTo(8); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(42); + assertThat(tuple._8).isEqualTo(8); } @Test public void shouldUpdate8() { final Tuple8 tuple = createIntTuple(1, 2, 3, 4, 5, 6, 7, 8).update8(42); - assertThat(tuple._1()).isEqualTo(1); - assertThat(tuple._2()).isEqualTo(2); - assertThat(tuple._3()).isEqualTo(3); - assertThat(tuple._4()).isEqualTo(4); - assertThat(tuple._5()).isEqualTo(5); - assertThat(tuple._6()).isEqualTo(6); - assertThat(tuple._7()).isEqualTo(7); - assertThat(tuple._8()).isEqualTo(42); + assertThat(tuple._1).isEqualTo(1); + assertThat(tuple._2).isEqualTo(2); + assertThat(tuple._3).isEqualTo(3); + assertThat(tuple._4).isEqualTo(4); + assertThat(tuple._5).isEqualTo(5); + assertThat(tuple._6).isEqualTo(6); + assertThat(tuple._7).isEqualTo(7); + assertThat(tuple._8).isEqualTo(42); } @Test diff --git a/javaslang/src/main/java/javaslang/collection/Collections.java b/javaslang/src/main/java/javaslang/collection/Collections.java index 65eae53d97..c7482d0785 100644 --- a/javaslang/src/main/java/javaslang/collection/Collections.java +++ b/javaslang/src/main/java/javaslang/collection/Collections.java @@ -73,7 +73,7 @@ public static > U mapKeys(Map source, U zer Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMerge, "valueMerge is null"); return source.foldLeft(zero, (acc, entry) -> { - final K2 k2 = keyMapper.apply(entry._1()); + final K2 k2 = keyMapper.apply(entry._1); final V v2 = entry._2; final Option v1 = acc.get(k2); final V v = v1.isDefined() ? valueMerge.apply(v1.get(), v2) : v2; diff --git a/javaslang/src/main/java/javaslang/collection/LinkedHashMap.java b/javaslang/src/main/java/javaslang/collection/LinkedHashMap.java index 10fe7283f0..854b550ac0 100644 --- a/javaslang/src/main/java/javaslang/collection/LinkedHashMap.java +++ b/javaslang/src/main/java/javaslang/collection/LinkedHashMap.java @@ -427,7 +427,7 @@ public LinkedHashMap put(K key, V value) { Queue> newList = list; HashMap newMap = map; if (containsKey(key)) { - newList = newList.filter(t -> !t._1.equals(key)); + newList = newList.filter(t -> !Objects.equals(t._1, key)); newMap = newMap.remove(key); } newList = newList.append(Tuple.of(key, value)); @@ -449,7 +449,7 @@ public LinkedHashMap put(Tuple2 entry, @Override public LinkedHashMap remove(K key) { if (containsKey(key)) { - final Queue> newList = list.removeFirst(t -> t._1.equals(key)); + final Queue> newList = list.removeFirst(t -> Objects.equals(t._1, key)); final HashMap newMap = map.remove(key); return wrap(newList, newMap); } else { diff --git a/javaslang/src/test/java/javaslang/collection/AbstractMapTest.java b/javaslang/src/test/java/javaslang/collection/AbstractMapTest.java index 61f0fd5aac..4b8d140dee 100644 --- a/javaslang/src/test/java/javaslang/collection/AbstractMapTest.java +++ b/javaslang/src/test/java/javaslang/collection/AbstractMapTest.java @@ -518,6 +518,12 @@ public void shouldPutTuple() { assertThat(emptyIntInt().put(Tuple.of(1, 2))).isEqualTo(emptyIntInt().put(1, 2)); } + @Test + public void shouldPutNullKeyIntoMapThatContainsNullKey() { + final Map map = mapOfPairs(1, "a", null, "b", 2, "c"); + assertThat(map.put(null, "!")).isEqualTo(mapOfPairs(1, "a", null, "!", 2, "c")); + } + // -- remove @Test @@ -527,6 +533,12 @@ public void shouldRemoveKey() { assertThat(src.remove(33)).isSameAs(src); } + @Test + public void shouldRemoveFromMapThatContainsFirstEntryHavingNullKey() { + final Map map = mapOfPairs(null, "a", 1, "b", 2, "c"); + assertThat(map.remove(1)).isEqualTo(mapOfPairs(null, "a", 2, "c")); + } + // -- removeAll @Test diff --git a/javaslang/src/test/java/javaslang/collection/TreeMapTest.java b/javaslang/src/test/java/javaslang/collection/TreeMapTest.java index c7c69afcbe..edbb70e4f3 100644 --- a/javaslang/src/test/java/javaslang/collection/TreeMapTest.java +++ b/javaslang/src/test/java/javaslang/collection/TreeMapTest.java @@ -10,9 +10,11 @@ import javaslang.Tuple2; import org.junit.Test; +import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.function.Function; import java.util.function.Supplier; @@ -35,7 +37,7 @@ java.util.Map javaEmptyMap() { @Override protected , T2> TreeMap emptyMap() { - return TreeMap.empty(); + return TreeMap.empty(nullsFirst()); } @Override @@ -57,34 +59,34 @@ protected boolean emptyShouldBeSingleton() { @SafeVarargs @Override protected final , V> TreeMap mapOfTuples(Tuple2... entries) { - return TreeMap.ofEntries(entries); + return TreeMap.ofEntries(nullsFirst(), entries); } @SuppressWarnings("varargs") @SafeVarargs @Override protected final , V> TreeMap mapOfEntries(java.util.Map.Entry... entries) { - return TreeMap.ofEntries(entries); + return TreeMap.ofEntries(nullsFirst(), entries); } @Override protected , V> TreeMap mapOfPairs(Object... pairs) { - return TreeMap.of(pairs); + return TreeMap.of(nullsFirst(), pairs); } @Override protected , V> TreeMap mapOf(K key, V value) { - return TreeMap.of(key, value); + return TreeMap.of(nullsFirst(), key, value); } @Override protected , V> TreeMap mapTabulate(int n, Function> f) { - return TreeMap.tabulate(n, f); + return TreeMap.tabulate(nullsFirst(), n, f); } @Override protected , V> TreeMap mapFill(int n, Supplier> s) { - return TreeMap.fill(n, s); + return TreeMap.fill(nullsFirst(), n, s); } // -- static narrow @@ -159,4 +161,12 @@ public void shouldReturnModifiedKeysMapWithNonUniqueMapperAndPredictableOrder() final Map expected = TreeMap.of(1, "3"); assertThat(actual).isEqualTo(expected); } + + // -- helpers + + // A comparator that allows null to be inserted into a TreeMap + private static > Comparator nullsFirst() { + return Comparator.nullsFirst((Comparator & Serializable) K::compareTo); + } + } diff --git a/javaslang/src/test/java/javaslang/control/OptionTest.java b/javaslang/src/test/java/javaslang/control/OptionTest.java index 82035c809c..f449170a86 100644 --- a/javaslang/src/test/java/javaslang/control/OptionTest.java +++ b/javaslang/src/test/java/javaslang/control/OptionTest.java @@ -70,41 +70,41 @@ public void shouldCreateNothing() { @Test public void shouldWrapIfTrue() { - assertThat(Option.some(null)).isEqualTo(Option.when(true, () -> null)); - assertThat(Option.some(null)).isEqualTo(Option.when(true, (Object) null)); + assertThat(Option.when(true, () -> null)).isEqualTo(Option.some(null)); + assertThat(Option.when(true, (Object) null)).isEqualTo(Option.some(null)); } @Test public void shouldNotWrapIfFalse() { - assertThat(Option.none()).isEqualTo(Option.when(false, () -> null)); - assertThat(Option.none()).isEqualTo(Option.when(false, (Object) null)); + assertThat(Option.when(false, () -> null)).isEqualTo(Option.none()); + assertThat(Option.when(false, (Object) null)).isEqualTo(Option.none()); } @Test public void shouldNotExecuteIfFalse() { - assertThat(Option.none()).isEqualTo(Option.when(false, () -> { + assertThat(Option.when(false, () -> { throw new RuntimeException(); - })); + })).isEqualTo(Option.none()); } @Test(expected = NullPointerException.class) public void shouldThrowExceptionOnWhenWithProvider() { - assertThat(Option.none()).isEqualTo(Option.when(false, (Supplier) null)); + assertThat(Option.when(false, (Supplier) null)).isEqualTo(Option.none()); } @Test public void shouldWrapEmptyOptional() { - assertThat(Option.none()).isEqualTo(Option.ofOptional(Optional.empty())); + assertThat(Option.ofOptional(Optional.empty())).isEqualTo(Option.none()); } @Test public void shouldWrapSomeOptional() { - assertThat(Option.of(1)).isEqualTo(Option.ofOptional(Optional.of(1))); + assertThat(Option.ofOptional(Optional.of(1))).isEqualTo(Option.of(1)); } @Test(expected = NullPointerException.class) public void shouldThrowExceptionOnNullOptional() { - assertThat(Option.none()).isEqualTo(Option.ofOptional(null)); + assertThat(Option.ofOptional(null)).isEqualTo(Option.none()); } // -- sequence