Modified:
pivot/trunk/core/test/org/apache/pivot/functional/monad/test/TryTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/functional/monad/test/TryTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/functional/monad/test/TryTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/functional/monad/test/TryTest.java
Tue Oct 31 19:15:47 2023
@@ -1,343 +1,343 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.functional.monad.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Iterator;
-import java.util.Random;
-
-import org.apache.pivot.functional.monad.Failure;
-import org.apache.pivot.functional.monad.None;
-import org.apache.pivot.functional.monad.Option;
-import org.apache.pivot.functional.monad.Some;
-import org.apache.pivot.functional.monad.Success;
-import org.apache.pivot.functional.monad.Try;
-import org.apache.pivot.functional.monad.TryCompanion;
-import org.junit.Test;
-
-public class TryTest {
- @Test
- public void companionTest() {
- TryCompanion<Object> t = TryCompanion.getInstance();
- assertNotNull(t);
- }
-
- @Test
- public void companionNullTest() {
- TryCompanion<Object> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- Try<Object> tn = t.fromValue(null);
- assertNotNull(tn);
- assertTrue(tn instanceof Success);
- assertTrue(tn.isSuccess());
- Object tnValue = tn.getValue();
- assertNull(tnValue);
- System.out.println("companionNullTest(), value stored is " + tnValue);
- }
-
- @Test
- public void companionObjectTest() {
- TryCompanion<Object> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- Try<Object> to = t.fromValue(new String("Hello"));
- assertNotNull(to);
- assertTrue(to instanceof Success);
- assertTrue(to.isSuccess());
- Object toValue = to.getValue();
- assertNotNull(toValue);
- assertTrue(toValue instanceof String);
- assertEquals(toValue, "Hello");
- System.out.println("companionObjectTest(), value stored is " +
toValue);
- }
-
- @Test
- public void companionStringTest() {
- TryCompanion<String> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- Try<String> ts = t.fromValue("Hello");
- assertNotNull(ts);
- assertTrue(ts instanceof Success);
- assertTrue(ts.isSuccess());
- String tsValue = ts.getValue();
- assertNotNull(tsValue);
- // assertTrue(tsValue instanceof String); // unnecessary
- assertEquals(tsValue, "Hello");
- System.out.println("companionStringTest(), value stored is " +
tsValue);
- }
-
- @Test
- public void companionFailureTest() {
- TryCompanion<String> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- RuntimeException re = new IllegalArgumentException("Sample
RuntimeException");
- Try<String> tf = t.fromValue(re);
- assertNotNull(tf);
- assertTrue(tf instanceof Failure);
- assertFalse(tf.isSuccess());
- try {
- String tfValue = tf.getValue(); // this will throw the
RuntimeException stored inside the Failure
- assertNotNull(tfValue); // never called
- } catch (RuntimeException e) {
- System.err.println("companionFailureTest(), value stored is " + e);
- assertNotNull(e); // unnecessary
-
- }
- }
-
- @Test
- public void companionRealUsageRandomTest() {
- TryCompanion<String> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- Try<String> ts = null;
- String value;
-
- // randomizing this test
- Random randomGenerator = new Random();
- int randomInt = randomGenerator.nextInt(100);
-
- // store the value (or the RuntimeException) in the Try instance
- try {
- // randomizing this test:
- // for even numbers a value will be generated,
- // but for odd numbers the value will be null so a call on it will
throw a RuntimeException
- if (randomInt % 2 == 0) {
- value = String.valueOf(randomInt);
- } else {
- value = null;
- throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
- }
-
- ts = t.fromValue(value);
- } catch (RuntimeException e) {
- ts = t.fromValue(e);
- }
-
- // verify the value stored
- System.out.println("companionRealUsageRandomTest(), value stored is a
success " + ts.isSuccess());
- try {
- String tsValue = ts.getValue(); // this will throw the
RuntimeException stored inside the Failure
- assertNotNull(tsValue); // called only when a real value
is stored (and not a RuntimeException)
- System.out.println("companionRealUsageRandomTest(), value stored
is " + tsValue);
- assertTrue(ts.isSuccess());
- } catch (RuntimeException e) {
- System.err.println("companionRealUsageRandomTest(), exception
stored is " + e);
- assertFalse(ts.isSuccess());
- }
- }
-
- @Test
- public void trySuccessTest() {
- // sample by direct instancing of Success/Failure classes, but
discouraged
- Try<String> ts = null;
-
- // store the value (or the RuntimeException) in the Try instance
- try {
- ts = new Success<>("Hello with Success");
- } catch (RuntimeException e) {
- // ts = new Success<>(e); // compile error, ok
- ts = new Failure<>(e);
- assertNotNull(e); // unnecessary
- }
-
- // verify the value stored
- System.out.println("trySuccessTest(), value stored is a success " +
ts.isSuccess());
- String tsValue;
- try {
- tsValue = ts.getValue(); // this will throw the RuntimeException
stored inside the Failure
- assertNotNull(tsValue); // called only when a real value is
stored (and not a RuntimeException)
- System.out.println("trySuccessTest(), value stored is " + tsValue);
- assertTrue(ts.isSuccess());
- } catch (RuntimeException e) {
- System.err.println("trySuccessTest(), exception stored is " + e);
- assertFalse(ts.isSuccess());
- }
- // test with alternative value
- tsValue = ts.getValueOrElse("Alternative value");
- assertEquals("Hello with Success", tsValue);
- tsValue = ts.getValueOrNull();
- assertEquals("Hello with Success", tsValue);
- }
-
- @Test
- public void tryFailureTest() {
- // sample by direct instancing of Success/Failure classes, but
discouraged
- Try<String> tf = null;
-
- // store the value (or the RuntimeException) in the Try instance
- try {
- throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
- } catch (RuntimeException e) {
- // ts = new Success<>(e); // compile error, ok
- tf = new Failure<>(e);
- assertNotNull(e); // unnecessary
- }
-
- // verify the value stored
- System.out.println("tryFailureTest(), value stored is a success " +
tf.isSuccess());
- String tsValue;
- try {
- tsValue = tf.getValue(); // this will throw the RuntimeException
stored inside the Failure
- assertNotNull(tsValue); // called only when a real value is
stored (and not a RuntimeException)
- System.out.println("tryFailureTest(), value stored is " + tsValue);
- assertTrue(tf.isSuccess());
- } catch (RuntimeException e) {
- System.err.println("tryFailureTest(), exception stored is " + e);
- assertFalse(tf.isSuccess());
- }
- // test with alternative value
- tsValue = tf.getValueOrElse("Alternative value");
- assertEquals("Alternative value", tsValue);
- tsValue = tf.getValueOrNull();
- assertEquals(null, tsValue);
- }
-
- @Test
- public void trySuccessIteratorTest() {
- // sample by direct instancing of Success/Failure classes, but
discouraged
- Try<String> ts = new Success<>("Hello with Success");
- System.out.println("trySuccessIteratorTest(), instance variable is " +
ts);
-
- // iterate and verify on the value stored
- Iterator<String> it = ts.iterator();
- assertNotNull(it);
- int i = 0;
- while (it.hasNext()) {
- String value = it.next();
- System.out.println("trySuccessIteratorTest(), value " + i + " from
iterator is " + value);
- assertNotNull(value);
- assertEquals("Hello with Success", value);
- i++;
- }
- assertEquals(i, 1);
-
- // another test
- i = 0;
- System.out.println("trySuccessIteratorTest(), another test");
- for (String value : ts) {
- System.out.println("trySuccessIteratorTest(), value " + i + " from
iterator is " + value);
- assertNotNull(value);
- assertEquals("Hello with Success", value);
- i++;
- }
- assertEquals(i, 1);
- }
-
- @Test
- public void tryFailureIteratorTest() {
- // sample by direct instancing of Success/Failure classes, but
discouraged
- Try<String> tf = null;
-
- // store the value (or the RuntimeException) in the Try instance
- try {
- throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
- } catch (RuntimeException e) {
- tf = new Failure<>(e);
- }
- System.out.println("tryFailureIteratorTest(), instance variable is " +
tf);
-
- // iterate and verify on the value stored
- Iterator<String> it = tf.iterator();
- assertNotNull(it);
- int i = 0;
- while (it.hasNext()) {
- // never executed in this case
- String value = it.next();
- System.out.println("tryFailureIteratorTest(), value " + i + " from
iterator is " + value);
- assertNull(value);
- i++;
- }
- assertEquals(i, 0);
-
- // another test
- i = 0;
- System.out.println("tryFailureIteratorTest(), another test");
- for (String value : tf) {
- // never executed in this case
- System.out.println("tryFailureIteratorTest(), value " + i + " from
iterator is " + value);
- assertNull(value);
- i++;
- }
- assertEquals(i, 0);
- }
-
- @Test
- public void companionSuccessToOptionTest() {
- TryCompanion<String> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- Try<String> ts = t.fromValue("Hello");
- Option<String> os = t.toOption(ts);
-
- // verify the value stored
- System.out.println("companionSuccessToOptionTest(), Try instance is "
+ ts);
- System.out.println("companionSuccessToOptionTest(), Option instance is
" + os);
-
- assertNotNull(ts);
- assertTrue(ts instanceof Success);
- assertTrue(ts.isSuccess());
-
- assertNotNull(os);
- assertTrue(os instanceof Some);
- assertTrue(os.hasValue());
-
- String osValue = os.getValue();
- assertNotNull(osValue);
- assertEquals(osValue, "Hello");
- System.out.println("companionSuccessToOptionTest(), value stored is "
+ osValue);
- }
-
- @Test
- public void companionFailureToOptionTest() {
- TryCompanion<String> t = TryCompanion.getInstance();
- assertNotNull(t);
-
- RuntimeException re = new IllegalArgumentException("Sample
RuntimeException");
- Try<String> tf = t.fromValue(re);
- Option<String> on = t.toOption(tf);
-
- // verify the value stored
- System.out.println("companionFailureToOptionTest(), Try instance is "
+ tf);
- System.out.println("companionFailureToOptionTest(), Option instance is
" + on);
-
- assertNotNull(tf);
- assertTrue(tf instanceof Failure);
- assertFalse(tf.isSuccess());
-
- assertNotNull(on);
- assertTrue(on instanceof None);
- assertFalse(on.hasValue());
-
- try {
- String onValue = on.getValue(); // this will throw a
RuntimeException for the non-value of None
- assertNotNull(onValue); // never called
- } catch (RuntimeException e) {
- System.err.println("companionFailureToOptionTest(), got
RuntimeException " + e);
- }
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.functional.monad.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.pivot.functional.monad.Failure;
+import org.apache.pivot.functional.monad.None;
+import org.apache.pivot.functional.monad.Option;
+import org.apache.pivot.functional.monad.Some;
+import org.apache.pivot.functional.monad.Success;
+import org.apache.pivot.functional.monad.Try;
+import org.apache.pivot.functional.monad.TryCompanion;
+import org.junit.Test;
+
+public class TryTest {
+ @Test
+ public void companionTest() {
+ TryCompanion<Object> t = TryCompanion.getInstance();
+ assertNotNull(t);
+ }
+
+ @Test
+ public void companionNullTest() {
+ TryCompanion<Object> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ Try<Object> tn = t.fromValue(null);
+ assertNotNull(tn);
+ assertTrue(tn instanceof Success);
+ assertTrue(tn.isSuccess());
+ Object tnValue = tn.getValue();
+ assertNull(tnValue);
+ System.out.println("companionNullTest(), value stored is " + tnValue);
+ }
+
+ @Test
+ public void companionObjectTest() {
+ TryCompanion<Object> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ Try<Object> to = t.fromValue(new String("Hello"));
+ assertNotNull(to);
+ assertTrue(to instanceof Success);
+ assertTrue(to.isSuccess());
+ Object toValue = to.getValue();
+ assertNotNull(toValue);
+ assertTrue(toValue instanceof String);
+ assertEquals(toValue, "Hello");
+ System.out.println("companionObjectTest(), value stored is " +
toValue);
+ }
+
+ @Test
+ public void companionStringTest() {
+ TryCompanion<String> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ Try<String> ts = t.fromValue("Hello");
+ assertNotNull(ts);
+ assertTrue(ts instanceof Success);
+ assertTrue(ts.isSuccess());
+ String tsValue = ts.getValue();
+ assertNotNull(tsValue);
+ // assertTrue(tsValue instanceof String); // unnecessary
+ assertEquals(tsValue, "Hello");
+ System.out.println("companionStringTest(), value stored is " +
tsValue);
+ }
+
+ @Test
+ public void companionFailureTest() {
+ TryCompanion<String> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ RuntimeException re = new IllegalArgumentException("Sample
RuntimeException");
+ Try<String> tf = t.fromValue(re);
+ assertNotNull(tf);
+ assertTrue(tf instanceof Failure);
+ assertFalse(tf.isSuccess());
+ try {
+ String tfValue = tf.getValue(); // this will throw the
RuntimeException stored inside the Failure
+ assertNotNull(tfValue); // never called
+ } catch (RuntimeException e) {
+ System.err.println("companionFailureTest(), value stored is " + e);
+ assertNotNull(e); // unnecessary
+
+ }
+ }
+
+ @Test
+ public void companionRealUsageRandomTest() {
+ TryCompanion<String> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ Try<String> ts = null;
+ String value;
+
+ // randomizing this test
+ Random randomGenerator = new Random();
+ int randomInt = randomGenerator.nextInt(100);
+
+ // store the value (or the RuntimeException) in the Try instance
+ try {
+ // randomizing this test:
+ // for even numbers a value will be generated,
+ // but for odd numbers the value will be null so a call on it will
throw a RuntimeException
+ if (randomInt % 2 == 0) {
+ value = String.valueOf(randomInt);
+ } else {
+ value = null;
+ throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
+ }
+
+ ts = t.fromValue(value);
+ } catch (RuntimeException e) {
+ ts = t.fromValue(e);
+ }
+
+ // verify the value stored
+ System.out.println("companionRealUsageRandomTest(), value stored is a
success " + ts.isSuccess());
+ try {
+ String tsValue = ts.getValue(); // this will throw the
RuntimeException stored inside the Failure
+ assertNotNull(tsValue); // called only when a real value
is stored (and not a RuntimeException)
+ System.out.println("companionRealUsageRandomTest(), value stored
is " + tsValue);
+ assertTrue(ts.isSuccess());
+ } catch (RuntimeException e) {
+ System.err.println("companionRealUsageRandomTest(), exception
stored is " + e);
+ assertFalse(ts.isSuccess());
+ }
+ }
+
+ @Test
+ public void trySuccessTest() {
+ // sample by direct instancing of Success/Failure classes, but
discouraged
+ Try<String> ts = null;
+
+ // store the value (or the RuntimeException) in the Try instance
+ try {
+ ts = new Success<>("Hello with Success");
+ } catch (RuntimeException e) {
+ // ts = new Success<>(e); // compile error, ok
+ ts = new Failure<>(e);
+ assertNotNull(e); // unnecessary
+ }
+
+ // verify the value stored
+ System.out.println("trySuccessTest(), value stored is a success " +
ts.isSuccess());
+ String tsValue;
+ try {
+ tsValue = ts.getValue(); // this will throw the RuntimeException
stored inside the Failure
+ assertNotNull(tsValue); // called only when a real value is
stored (and not a RuntimeException)
+ System.out.println("trySuccessTest(), value stored is " + tsValue);
+ assertTrue(ts.isSuccess());
+ } catch (RuntimeException e) {
+ System.err.println("trySuccessTest(), exception stored is " + e);
+ assertFalse(ts.isSuccess());
+ }
+ // test with alternative value
+ tsValue = ts.getValueOrElse("Alternative value");
+ assertEquals("Hello with Success", tsValue);
+ tsValue = ts.getValueOrNull();
+ assertEquals("Hello with Success", tsValue);
+ }
+
+ @Test
+ public void tryFailureTest() {
+ // sample by direct instancing of Success/Failure classes, but
discouraged
+ Try<String> tf = null;
+
+ // store the value (or the RuntimeException) in the Try instance
+ try {
+ throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
+ } catch (RuntimeException e) {
+ // ts = new Success<>(e); // compile error, ok
+ tf = new Failure<>(e);
+ assertNotNull(e); // unnecessary
+ }
+
+ // verify the value stored
+ System.out.println("tryFailureTest(), value stored is a success " +
tf.isSuccess());
+ String tsValue;
+ try {
+ tsValue = tf.getValue(); // this will throw the RuntimeException
stored inside the Failure
+ assertNotNull(tsValue); // called only when a real value is
stored (and not a RuntimeException)
+ System.out.println("tryFailureTest(), value stored is " + tsValue);
+ assertTrue(tf.isSuccess());
+ } catch (RuntimeException e) {
+ System.err.println("tryFailureTest(), exception stored is " + e);
+ assertFalse(tf.isSuccess());
+ }
+ // test with alternative value
+ tsValue = tf.getValueOrElse("Alternative value");
+ assertEquals("Alternative value", tsValue);
+ tsValue = tf.getValueOrNull();
+ assertEquals(null, tsValue);
+ }
+
+ @Test
+ public void trySuccessIteratorTest() {
+ // sample by direct instancing of Success/Failure classes, but
discouraged
+ Try<String> ts = new Success<>("Hello with Success");
+ System.out.println("trySuccessIteratorTest(), instance variable is " +
ts);
+
+ // iterate and verify on the value stored
+ Iterator<String> it = ts.iterator();
+ assertNotNull(it);
+ int i = 0;
+ while (it.hasNext()) {
+ String value = it.next();
+ System.out.println("trySuccessIteratorTest(), value " + i + " from
iterator is " + value);
+ assertNotNull(value);
+ assertEquals("Hello with Success", value);
+ i++;
+ }
+ assertEquals(i, 1);
+
+ // another test
+ i = 0;
+ System.out.println("trySuccessIteratorTest(), another test");
+ for (String value : ts) {
+ System.out.println("trySuccessIteratorTest(), value " + i + " from
iterator is " + value);
+ assertNotNull(value);
+ assertEquals("Hello with Success", value);
+ i++;
+ }
+ assertEquals(i, 1);
+ }
+
+ @Test
+ public void tryFailureIteratorTest() {
+ // sample by direct instancing of Success/Failure classes, but
discouraged
+ Try<String> tf = null;
+
+ // store the value (or the RuntimeException) in the Try instance
+ try {
+ throw new NullPointerException("Sample RuntimeException"); //
simulate an exception here
+ } catch (RuntimeException e) {
+ tf = new Failure<>(e);
+ }
+ System.out.println("tryFailureIteratorTest(), instance variable is " +
tf);
+
+ // iterate and verify on the value stored
+ Iterator<String> it = tf.iterator();
+ assertNotNull(it);
+ int i = 0;
+ while (it.hasNext()) {
+ // never executed in this case
+ String value = it.next();
+ System.out.println("tryFailureIteratorTest(), value " + i + " from
iterator is " + value);
+ assertNull(value);
+ i++;
+ }
+ assertEquals(i, 0);
+
+ // another test
+ i = 0;
+ System.out.println("tryFailureIteratorTest(), another test");
+ for (String value : tf) {
+ // never executed in this case
+ System.out.println("tryFailureIteratorTest(), value " + i + " from
iterator is " + value);
+ assertNull(value);
+ i++;
+ }
+ assertEquals(i, 0);
+ }
+
+ @Test
+ public void companionSuccessToOptionTest() {
+ TryCompanion<String> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ Try<String> ts = t.fromValue("Hello");
+ Option<String> os = t.toOption(ts);
+
+ // verify the value stored
+ System.out.println("companionSuccessToOptionTest(), Try instance is "
+ ts);
+ System.out.println("companionSuccessToOptionTest(), Option instance is
" + os);
+
+ assertNotNull(ts);
+ assertTrue(ts instanceof Success);
+ assertTrue(ts.isSuccess());
+
+ assertNotNull(os);
+ assertTrue(os instanceof Some);
+ assertTrue(os.hasValue());
+
+ String osValue = os.getValue();
+ assertNotNull(osValue);
+ assertEquals(osValue, "Hello");
+ System.out.println("companionSuccessToOptionTest(), value stored is "
+ osValue);
+ }
+
+ @Test
+ public void companionFailureToOptionTest() {
+ TryCompanion<String> t = TryCompanion.getInstance();
+ assertNotNull(t);
+
+ RuntimeException re = new IllegalArgumentException("Sample
RuntimeException");
+ Try<String> tf = t.fromValue(re);
+ Option<String> on = t.toOption(tf);
+
+ // verify the value stored
+ System.out.println("companionFailureToOptionTest(), Try instance is "
+ tf);
+ System.out.println("companionFailureToOptionTest(), Option instance is
" + on);
+
+ assertNotNull(tf);
+ assertTrue(tf instanceof Failure);
+ assertFalse(tf.isSuccess());
+
+ assertNotNull(on);
+ assertTrue(on instanceof None);
+ assertFalse(on.hasValue());
+
+ try {
+ String onValue = on.getValue(); // this will throw a
RuntimeException for the non-value of None
+ assertNotNull(onValue); // never called
+ } catch (RuntimeException e) {
+ System.err.println("companionFailureToOptionTest(), got
RuntimeException " + e);
+ }
+
+ }
+
+}
Propchange:
pivot/trunk/core/test/org/apache/pivot/functional/monad/test/TryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: pivot/trunk/core/test/org/apache/pivot/text/test/CharSpanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
pivot/trunk/core/test/org/apache/pivot/util/test/BooleanResultTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/BooleanResultTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/BooleanResultTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/BooleanResultTest.java Tue
Oct 31 19:15:47 2023
@@ -1,83 +1,83 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-
-import org.apache.pivot.util.BooleanResult;
-
-
-public class BooleanResultTest {
- private enum Operation {
- OR,
- AND,
- XOR,
- NOT,
- CLEAR,
- SET
- }
-
- private void operateAndTest(BooleanResult result, boolean value, Operation
op, boolean expectedResult) {
- switch (op) {
- case OR:
- result.or(value);
- break;
- case AND:
- result.and(value);
- break;
- case XOR:
- result.xor(value);
- break;
- case NOT:
- result.not();
- break;
- case CLEAR:
- result.clear();
- break;
- case SET:
- result.set(value);
- break;
- default:
- assertFalse("Invalid operator " + op, true);
- break;
- }
- assertEquals(result.get(), expectedResult);
- }
-
- @Test
- public void test() {
- BooleanResult result = new BooleanResult();
- operateAndTest(result, false, Operation.OR, false);
- operateAndTest(result, true, Operation.OR, true);
- operateAndTest(result, true, Operation.XOR, false);
- operateAndTest(result, false /* ignored */, Operation.NOT, true);
- operateAndTest(result, true, Operation.AND, true);
- operateAndTest(result, false, Operation.SET, false);
- operateAndTest(result, true, Operation.SET, true);
- operateAndTest(result, true /* ignored */, Operation.CLEAR, false);
-
- BooleanResult result2 = new BooleanResult(true);
- assertEquals(result2.get(), true);
-
- result2.clear();
- assertEquals(result2.get(), false);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+import org.apache.pivot.util.BooleanResult;
+
+
+public class BooleanResultTest {
+ private enum Operation {
+ OR,
+ AND,
+ XOR,
+ NOT,
+ CLEAR,
+ SET
+ }
+
+ private void operateAndTest(BooleanResult result, boolean value, Operation
op, boolean expectedResult) {
+ switch (op) {
+ case OR:
+ result.or(value);
+ break;
+ case AND:
+ result.and(value);
+ break;
+ case XOR:
+ result.xor(value);
+ break;
+ case NOT:
+ result.not();
+ break;
+ case CLEAR:
+ result.clear();
+ break;
+ case SET:
+ result.set(value);
+ break;
+ default:
+ assertFalse("Invalid operator " + op, true);
+ break;
+ }
+ assertEquals(result.get(), expectedResult);
+ }
+
+ @Test
+ public void test() {
+ BooleanResult result = new BooleanResult();
+ operateAndTest(result, false, Operation.OR, false);
+ operateAndTest(result, true, Operation.OR, true);
+ operateAndTest(result, true, Operation.XOR, false);
+ operateAndTest(result, false /* ignored */, Operation.NOT, true);
+ operateAndTest(result, true, Operation.AND, true);
+ operateAndTest(result, false, Operation.SET, false);
+ operateAndTest(result, true, Operation.SET, true);
+ operateAndTest(result, true /* ignored */, Operation.CLEAR, false);
+
+ BooleanResult result2 = new BooleanResult(true);
+ assertEquals(result2.get(), true);
+
+ result2.clear();
+ assertEquals(result2.get(), false);
+ }
+
+}
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/BooleanResultTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/CalendarDateTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/CalendarDateTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/CalendarDateTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/CalendarDateTest.java Tue
Oct 31 19:15:47 2023
@@ -1,128 +1,128 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.util.TimeZone;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import org.apache.pivot.util.CalendarDate;
-import org.apache.pivot.util.Time;
-
-
-public class CalendarDateTest {
- private static final String D1 = "1941-12-07";
- private static final String D2 = "1929-10-29";
- private static final String D3 = "2008-09-29";
- private static final String D4 = "1945-08-14";
- private static final String D5 = "2019-12-06";
- private static final int DAYS_FROM_D1_TO_D5 = 28_488;
-
- @Test
- public void test1() {
- CalendarDate.Range r1 = new CalendarDate.Range(D1);
- CalendarDate.Range r1a = new CalendarDate.Range(D1, D1);
- CalendarDate.Range r2 = new CalendarDate.Range(D2, D3);
- CalendarDate.Range r3 = CalendarDate.Range.decode("{ \"start\" :
\"1929-10-29\", \"end\" : \"2008-09-29\"}");
- CalendarDate.Range r3a = CalendarDate.Range.decode("[ \"1929-10-29\",
\"2008-09-29\" ]");
- CalendarDate.Range r3b = CalendarDate.Range.decode("1929-10-29,
2008-09-29");
-
- CalendarDate cd1 = CalendarDate.decode(D1);
- CalendarDate cd2 = CalendarDate.decode(D2);
- CalendarDate cd3 = CalendarDate.decode(D3);
-
- assertTrue(r2.contains(r1));
- assertEquals(r1, r1a);
- assertEquals(r1.getLength(), 1);
- assertTrue(r2.normalize().equals(r2));
- // TODO: more tests of range methods: intersects, etc.
-
- assertEquals(r3, r3a);
- assertEquals(r3, r3b);
- assertEquals(r3a, r3b);
-
- assertEquals(cd1.year, 1941);
- assertEquals(cd1.month, 11);
- assertEquals(cd1.day, 6);
- assertEquals(cd1.toString(), D1);
- }
-
- @Test
- public void test2() {
- // PIVOT-1010: test interaction with LocalDate, etc. (new Java 8
classes)
- LocalDate ld1 = LocalDate.of(1941, 12, 7);
- CalendarDate cd1 = new CalendarDate(ld1);
- CalendarDate cd1a = CalendarDate.decode(D1);
- LocalDate ld1a = cd1a.toLocalDate();
-
- assertEquals(cd1, cd1a);
- assertEquals(ld1, ld1a);
-
- Time t1 = Time.decode("07:48:00");
- LocalDateTime dt1 = LocalDateTime.of(1941, 12, 7, 7, 48, 0);
- LocalDateTime dt1a = cd1.toLocalDateTime(t1);
-
- assertEquals(dt1, dt1a);
- }
-
- @Test
- public void test3() {
- // Testing new stuff in CalendarDate that tries to deal with time zones
- // more effectively
- TimeZone gmtZone = CalendarDate.TIMEZONE_GMT;
- TimeZone pstZone = TimeZone.getTimeZone("America/Los_Angeles");
- CalendarDate d1 = new CalendarDate(1941, 11, 6, gmtZone);
- CalendarDate d2 = new CalendarDate(1941, 11, 6, pstZone);
- CalendarDate d3 = new CalendarDate(1945, 7, 13, gmtZone);
- CalendarDate d4 = d1.add(1346);
- CalendarDate d5 = d2.add(1346);
-
- // First we should establish that dates don't depend on timezone for
equality
- // nor do their string representations
- assertTrue(d1.equals(d2));
- assertEquals(d1.toString(), d2.toString());
-
- // Now, establish whether (or not) timezones might make a difference
in durations
- assertEquals(d3.subtract(d1), 1346);
- // Surprise! they do!
- assertEquals(d3.subtract(d2), 1345);
- assertEquals(d4, d5);
- }
-
- @Test
- public void test4() {
- // Now let's test some of the other duration-related methods
- CalendarDate d1 = CalendarDate.decode(D1);
- CalendarDate d2 = d1.addMonths(44).add(7);
- CalendarDate d3 = d1.addYears(3).addMonths(8).add(7);
- CalendarDate d4 = CalendarDate.decode(D4);
- CalendarDate d5 = CalendarDate.decode(D5);
-
- assertEquals(d2, d3);
- assertEquals(d2, d4);
- assertEquals(d3, d4);
-
- assertEquals(d5.subtract(d1), DAYS_FROM_D1_TO_D5);
- assertEquals(d1.add(DAYS_FROM_D1_TO_D5), d5);
- assertEquals(d1.add(DAYS_FROM_D1_TO_D5).add(-DAYS_FROM_D1_TO_D5), d1);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.TimeZone;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import org.apache.pivot.util.CalendarDate;
+import org.apache.pivot.util.Time;
+
+
+public class CalendarDateTest {
+ private static final String D1 = "1941-12-07";
+ private static final String D2 = "1929-10-29";
+ private static final String D3 = "2008-09-29";
+ private static final String D4 = "1945-08-14";
+ private static final String D5 = "2019-12-06";
+ private static final int DAYS_FROM_D1_TO_D5 = 28_488;
+
+ @Test
+ public void test1() {
+ CalendarDate.Range r1 = new CalendarDate.Range(D1);
+ CalendarDate.Range r1a = new CalendarDate.Range(D1, D1);
+ CalendarDate.Range r2 = new CalendarDate.Range(D2, D3);
+ CalendarDate.Range r3 = CalendarDate.Range.decode("{ \"start\" :
\"1929-10-29\", \"end\" : \"2008-09-29\"}");
+ CalendarDate.Range r3a = CalendarDate.Range.decode("[ \"1929-10-29\",
\"2008-09-29\" ]");
+ CalendarDate.Range r3b = CalendarDate.Range.decode("1929-10-29,
2008-09-29");
+
+ CalendarDate cd1 = CalendarDate.decode(D1);
+ CalendarDate cd2 = CalendarDate.decode(D2);
+ CalendarDate cd3 = CalendarDate.decode(D3);
+
+ assertTrue(r2.contains(r1));
+ assertEquals(r1, r1a);
+ assertEquals(r1.getLength(), 1);
+ assertTrue(r2.normalize().equals(r2));
+ // TODO: more tests of range methods: intersects, etc.
+
+ assertEquals(r3, r3a);
+ assertEquals(r3, r3b);
+ assertEquals(r3a, r3b);
+
+ assertEquals(cd1.year, 1941);
+ assertEquals(cd1.month, 11);
+ assertEquals(cd1.day, 6);
+ assertEquals(cd1.toString(), D1);
+ }
+
+ @Test
+ public void test2() {
+ // PIVOT-1010: test interaction with LocalDate, etc. (new Java 8
classes)
+ LocalDate ld1 = LocalDate.of(1941, 12, 7);
+ CalendarDate cd1 = new CalendarDate(ld1);
+ CalendarDate cd1a = CalendarDate.decode(D1);
+ LocalDate ld1a = cd1a.toLocalDate();
+
+ assertEquals(cd1, cd1a);
+ assertEquals(ld1, ld1a);
+
+ Time t1 = Time.decode("07:48:00");
+ LocalDateTime dt1 = LocalDateTime.of(1941, 12, 7, 7, 48, 0);
+ LocalDateTime dt1a = cd1.toLocalDateTime(t1);
+
+ assertEquals(dt1, dt1a);
+ }
+
+ @Test
+ public void test3() {
+ // Testing new stuff in CalendarDate that tries to deal with time zones
+ // more effectively
+ TimeZone gmtZone = CalendarDate.TIMEZONE_GMT;
+ TimeZone pstZone = TimeZone.getTimeZone("America/Los_Angeles");
+ CalendarDate d1 = new CalendarDate(1941, 11, 6, gmtZone);
+ CalendarDate d2 = new CalendarDate(1941, 11, 6, pstZone);
+ CalendarDate d3 = new CalendarDate(1945, 7, 13, gmtZone);
+ CalendarDate d4 = d1.add(1346);
+ CalendarDate d5 = d2.add(1346);
+
+ // First we should establish that dates don't depend on timezone for
equality
+ // nor do their string representations
+ assertTrue(d1.equals(d2));
+ assertEquals(d1.toString(), d2.toString());
+
+ // Now, establish whether (or not) timezones might make a difference
in durations
+ assertEquals(d3.subtract(d1), 1346);
+ // Surprise! they do!
+ assertEquals(d3.subtract(d2), 1345);
+ assertEquals(d4, d5);
+ }
+
+ @Test
+ public void test4() {
+ // Now let's test some of the other duration-related methods
+ CalendarDate d1 = CalendarDate.decode(D1);
+ CalendarDate d2 = d1.addMonths(44).add(7);
+ CalendarDate d3 = d1.addYears(3).addMonths(8).add(7);
+ CalendarDate d4 = CalendarDate.decode(D4);
+ CalendarDate d5 = CalendarDate.decode(D5);
+
+ assertEquals(d2, d3);
+ assertEquals(d2, d4);
+ assertEquals(d3, d4);
+
+ assertEquals(d5.subtract(d1), DAYS_FROM_D1_TO_D5);
+ assertEquals(d1.add(DAYS_FROM_D1_TO_D5), d5);
+ assertEquals(d1.add(DAYS_FROM_D1_TO_D5).add(-DAYS_FROM_D1_TO_D5), d1);
+ }
+}
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/CalendarDateTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/CharUtilsTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/CharUtilsTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/CharUtilsTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/CharUtilsTest.java Tue Oct
31 19:15:47 2023
@@ -1,76 +1,76 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-
-import org.apache.pivot.text.CharSpan;
-import org.apache.pivot.util.CharUtils;
-
-/**
- * Test the word selection and navigation methods in {@link CharUtils}.
- */
-public class CharUtilsTest {
- private static final String TEST_STRING =
- "A successful man is one who can lay a firm foundation with the bricks
others have thrown at him."
- + " -David Brinkley\n";
-
- @Test
- public void testSelectWord() {
- CharSpan nullSpan = CharUtils.selectWord(TEST_STRING, -1);
- assertNull("null span from negative start", nullSpan);
-
- CharSpan firstWordSpan = new CharSpan(0, 1);
- CharSpan firstBlankSpan = new CharSpan(1, 1);
- CharSpan span0 = CharUtils.selectWord(TEST_STRING, 0);
- CharSpan span1 = CharUtils.selectWord(TEST_STRING, 1);
- assertEquals("one letter word", firstWordSpan, span0);
- assertEquals("first blank", firstBlankSpan, span1);
-
- CharSpan longWordSpan = new CharSpan(2, 10);
- CharSpan spanLong1 = CharUtils.selectWord(TEST_STRING, 5);
- CharSpan spanLong2 = CharUtils.selectWord(TEST_STRING, 11);
- assertEquals("long word", longWordSpan, spanLong1);
- assertEquals("same long word", spanLong1, spanLong2);
-
- CharSpan lastWordSpan = new CharSpan(TEST_STRING.length() - 9, 8);
- CharSpan spanLast = CharUtils.selectWord(TEST_STRING,
TEST_STRING.length());
- assertEquals("last word", lastWordSpan, spanLast);
- }
-
- @Test
- public void testFindNextWord() {
- int length = TEST_STRING.length();
- int end = CharUtils.findNextWord(TEST_STRING, length - 4);
- assertEquals("next word at end", length, end);
-
- int midWord = CharUtils.findNextWord(TEST_STRING, 45);
- assertEquals("next word", 54, midWord);
- }
-
- @Test
- public void testFindPriorWord() {
- int first = CharUtils.findPriorWord(TEST_STRING, 2);
- assertEquals("first prior word", 0, first);
-
- int third = CharUtils.findPriorWord(TEST_STRING, 14);
- assertEquals("third prior word", 13, third);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+import org.apache.pivot.text.CharSpan;
+import org.apache.pivot.util.CharUtils;
+
+/**
+ * Test the word selection and navigation methods in {@link CharUtils}.
+ */
+public class CharUtilsTest {
+ private static final String TEST_STRING =
+ "A successful man is one who can lay a firm foundation with the bricks
others have thrown at him."
+ + " -David Brinkley\n";
+
+ @Test
+ public void testSelectWord() {
+ CharSpan nullSpan = CharUtils.selectWord(TEST_STRING, -1);
+ assertNull("null span from negative start", nullSpan);
+
+ CharSpan firstWordSpan = new CharSpan(0, 1);
+ CharSpan firstBlankSpan = new CharSpan(1, 1);
+ CharSpan span0 = CharUtils.selectWord(TEST_STRING, 0);
+ CharSpan span1 = CharUtils.selectWord(TEST_STRING, 1);
+ assertEquals("one letter word", firstWordSpan, span0);
+ assertEquals("first blank", firstBlankSpan, span1);
+
+ CharSpan longWordSpan = new CharSpan(2, 10);
+ CharSpan spanLong1 = CharUtils.selectWord(TEST_STRING, 5);
+ CharSpan spanLong2 = CharUtils.selectWord(TEST_STRING, 11);
+ assertEquals("long word", longWordSpan, spanLong1);
+ assertEquals("same long word", spanLong1, spanLong2);
+
+ CharSpan lastWordSpan = new CharSpan(TEST_STRING.length() - 9, 8);
+ CharSpan spanLast = CharUtils.selectWord(TEST_STRING,
TEST_STRING.length());
+ assertEquals("last word", lastWordSpan, spanLast);
+ }
+
+ @Test
+ public void testFindNextWord() {
+ int length = TEST_STRING.length();
+ int end = CharUtils.findNextWord(TEST_STRING, length - 4);
+ assertEquals("next word at end", length, end);
+
+ int midWord = CharUtils.findNextWord(TEST_STRING, 45);
+ assertEquals("next word", 54, midWord);
+ }
+
+ @Test
+ public void testFindPriorWord() {
+ int first = CharUtils.findPriorWord(TEST_STRING, 2);
+ assertEquals("first prior word", 0, first);
+
+ int third = CharUtils.findPriorWord(TEST_STRING, 14);
+ assertEquals("third prior word", 13, third);
+ }
+}
Propchange: pivot/trunk/core/test/org/apache/pivot/util/test/CharUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java Tue
Oct 31 19:15:47 2023
@@ -1,51 +1,51 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import org.junit.Test;
-
-import org.apache.pivot.util.EmptyIterator;
-
-
-public class EmptyIteratorTest {
- @Test
- public void basicTest() {
- Iterator<String> iter = new EmptyIterator<String>();
- assertTrue(!iter.hasNext());
- try {
- iter.next();
- assertTrue(false);
- } catch (NoSuchElementException nsee) {
- assertTrue(true);
- }
- }
-
- @Test
- public void removeTest() {
- Iterator<String> iter = new EmptyIterator<String>();
- try {
- iter.remove();
- assertTrue(false);
- } catch (UnsupportedOperationException uoe) {
- assertTrue(true);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.junit.Test;
+
+import org.apache.pivot.util.EmptyIterator;
+
+
+public class EmptyIteratorTest {
+ @Test
+ public void basicTest() {
+ Iterator<String> iter = new EmptyIterator<String>();
+ assertTrue(!iter.hasNext());
+ try {
+ iter.next();
+ assertTrue(false);
+ } catch (NoSuchElementException nsee) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void removeTest() {
+ Iterator<String> iter = new EmptyIterator<String>();
+ try {
+ iter.remove();
+ assertTrue(false);
+ } catch (UnsupportedOperationException uoe) {
+ assertTrue(true);
+ }
+ }
+}
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
Tue Oct 31 19:15:47 2023
@@ -1,74 +1,74 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Iterator;
-import org.junit.Test;
-
-import org.apache.pivot.collections.ArrayList;
-import org.apache.pivot.util.ImmutableIterator;
-
-
-/**
- * Tests of the {@link ImmutableIterator} class, which is used
- * for iteration over many things, when we don't need/want to
- * modify the object we're iterating over.
- */
-public class ImmutableIteratorTest {
- /**
- * Run the basic tests.
- */
- @Test
- public void test() {
- ArrayList<String> strings = new ArrayList<>();
- strings.add("Tom");
- strings.add("Dick");
- strings.add("Harry");
- strings.forEach(value -> System.out.println(value));
-
- Iterator<String> iter = strings.iterator();
- assertEquals(iter.hasNext(), true);
- assertEquals(iter.next(), "Tom");
- assertEquals(iter.hasNext(), true);
- assertEquals(iter.next(), "Dick");
- assertEquals(iter.hasNext(), true);
- assertEquals(iter.next(), "Harry");
- assertEquals(iter.hasNext(), false);
-
- iter = strings.iterator();
- ImmutableIterator<String> iiter = new ImmutableIterator<>(iter);
-
- try {
- iiter.remove();
- assertTrue(false);
- } catch (UnsupportedOperationException uoe) {
- assertTrue(true);
- }
-
- assertEquals(iiter.hasNext(), true);
- assertEquals(iiter.next(), "Tom");
- assertEquals(iiter.hasNext(), true);
- assertEquals(iiter.next(), "Dick");
- assertEquals(iiter.hasNext(), true);
- assertEquals(iiter.next(), "Harry");
- assertEquals(iiter.hasNext(), false);
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Iterator;
+import org.junit.Test;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.util.ImmutableIterator;
+
+
+/**
+ * Tests of the {@link ImmutableIterator} class, which is used
+ * for iteration over many things, when we don't need/want to
+ * modify the object we're iterating over.
+ */
+public class ImmutableIteratorTest {
+ /**
+ * Run the basic tests.
+ */
+ @Test
+ public void test() {
+ ArrayList<String> strings = new ArrayList<>();
+ strings.add("Tom");
+ strings.add("Dick");
+ strings.add("Harry");
+ strings.forEach(value -> System.out.println(value));
+
+ Iterator<String> iter = strings.iterator();
+ assertEquals(iter.hasNext(), true);
+ assertEquals(iter.next(), "Tom");
+ assertEquals(iter.hasNext(), true);
+ assertEquals(iter.next(), "Dick");
+ assertEquals(iter.hasNext(), true);
+ assertEquals(iter.next(), "Harry");
+ assertEquals(iter.hasNext(), false);
+
+ iter = strings.iterator();
+ ImmutableIterator<String> iiter = new ImmutableIterator<>(iter);
+
+ try {
+ iiter.remove();
+ assertTrue(false);
+ } catch (UnsupportedOperationException uoe) {
+ assertTrue(true);
+ }
+
+ assertEquals(iiter.hasNext(), true);
+ assertEquals(iiter.next(), "Tom");
+ assertEquals(iiter.hasNext(), true);
+ assertEquals(iiter.next(), "Dick");
+ assertEquals(iiter.hasNext(), true);
+ assertEquals(iiter.next(), "Harry");
+ assertEquals(iiter.hasNext(), false);
+ }
+}
+
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/ListenerListTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/VersionTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/VersionTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/VersionTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/VersionTest.java Tue Oct
31 19:15:47 2023
@@ -1,232 +1,232 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.junit.Test;
-
-import org.apache.pivot.util.Version;
-
-
-/**
- * Tests of the {@link Version} class.
- */
-public class VersionTest {
- /**
- * Test version decode that happens at application startup.
- */
- @Test
- public void testApplicationStartup() {
- // These are the things that happen right away for ApplicationContext
- // and therefore would break immediately if Version was broken (as did
- // happen for Java 8u131).
- // Get the JVM version
- Version jvmVersion =
Version.decode(System.getProperty("java.vm.version"));
- System.out.format("JVM Version: %1$s%n", jvmVersion.toString());
- Version pivotVersion = null;
- Package corePackage = Version.class.getPackage();
-
- // Get the Java runtime version
- Version javaVersion =
Version.decode(System.getProperty("java.version"));
- System.out.format("Java version: %1$s%n", javaVersion);
-
- // Get the Pivot version
- String version = corePackage.getImplementationVersion();
- if (version == null) {
- pivotVersion = new Version(0, 0, 0, 0);
- assertEquals("default Pivot version", "0.0.0_00",
pivotVersion.toString());
- } else {
- pivotVersion = Version.decode(version);
- System.out.format("Pivot Version: %1$s%n", pivotVersion);
- }
- }
-
- /** The Java version string that broke the old code (build overflows a
byte). */
- private static final String S1_8_131 = "1.8.0_131";
- /** Decoding that breaking version string. */
- private static final Version V1 = Version.decode(S1_8_131);
- /** The version object that should match that decoded value. */
- private static final Version V8_131 = new Version(1, 8, 0, 131);
- /** A version 1.0 string. */
- private static final String S1_0_0 = "1.0.0_00";
- /** Decoding version 1. */
- private static final Version V0 = Version.decode(S1_0_0);
- /** The version object that should match version 1. */
- private static final Version V1_0 = new Version(1, 0, 0, 0);
- /** The null/empty version object. */
- private static final Version EMPTY = new Version(0, 0, 0, 0);
-
- /**
- * Test basic parsing (including our overflow fail case).
- */
- @Test
- public void testVersionParsing() {
- assertEquals("version decode", V8_131, V1);
- assertEquals("version to string", V8_131.toString(), S1_8_131);
-
- assertEquals("version 0 decode", V1_0, V0);
- assertEquals("version 0 to string", S1_0_0, V1_0.toString());
-
- // New Java 9 version number scheme
- String j9 = "9.0.1+11";
- Version vj9 = Version.decode(j9);
- Version vj90 = new Version(9, 0, 1, 0);
- assertEquals("Java version 9 decode", vj90, vj9);
- assertEquals("Java version 9 to string", "9.0.1_00-11",
vj9.toString());
- }
-
- /**
- * Test overflows of the new short values.
- */
- @Test
- public void testLimits() {
- Version vMax = new Version(32767, 32767, 32767, 32767);
- String sMax = "32767.32767.32767_32767";
- assertEquals("max versions", sMax, vMax.toString());
- IllegalArgumentException argFailure = null;
- try {
- Version vOverflow = new Version(32768, 0, 1, 0);
- } catch (IllegalArgumentException iae) {
- argFailure = iae;
- }
- assertNotNull("illegal argument exception", argFailure);
- assertEquals("exception message",
- "majorVersion must be less than or equal 32767.",
- argFailure.getMessage());
- }
-
- /**
- * Test {@link Version#getNumber}.
- */
- @Test
- public void testNumber() {
- Version vNum = new Version(2, 1, 1, 100);
- long num = vNum.getNumber();
- System.out.format("test getNumber(): %1$s -> %2$d (0x%2$016x)%n",
vNum, num);
- assertEquals("long number", 0x0002000100010064L, num);
- }
-
- /** Taken from PIVOT-996 test case -- the build suffix ... */
- private static final String PIVOT_996_SUFFIX = "25.51-b14";
- /** PIVOT-996 complete input string. */
- private static final String PIVOT_996_INPUT = "8.1.028 " +
PIVOT_996_SUFFIX;
- /** What we expect from PIVOT-996 test case on output. */
- private static final String PIVOT_996_OUTPUT = "8.1.28_00-" +
PIVOT_996_SUFFIX;
-
- /**
- * Other test cases (from issues, or other sources).
- */
- @Test
- public void testOtherVersions() {
- Version jvmVersionParsed = Version.decode(PIVOT_996_INPUT);
- Version jvmVersionExplicit = new Version(8, 1, 28, 0,
PIVOT_996_SUFFIX);
- String parsedToString = jvmVersionParsed.toString();
-
- System.out.println("Information only: our version = " +
Version.implementationVersion());
-
- assertEquals("PIVOT-996 test case", jvmVersionExplicit,
jvmVersionParsed);
- System.out.format("PIVOT-996 parsed/toString: %1$s, expected: %2$s%n",
- parsedToString, PIVOT_996_OUTPUT);
- assertEquals("PIVOT-996 toString", PIVOT_996_OUTPUT, parsedToString);
-
- Pattern versionPattern = Pattern.compile("(\\d+(\\.\\d+\\.\\d+)?).*");
- String sysJavaVersion = System.getProperty("java.runtime.version");
- Version javaVersion = Version.decode(sysJavaVersion);
- String formattedJavaVersion = javaVersion.toString();
- String simpleVersion = javaVersion.simpleToString();
- System.out.format("Java Runtime version (parsed and formatted): %1$s,
raw: %2$s, simple: %3$s%n",
- formattedJavaVersion, sysJavaVersion, simpleVersion);
- Matcher sysMatcher = versionPattern.matcher(sysJavaVersion);
- boolean matches = sysMatcher.matches()
- && simpleVersion.startsWith(sysMatcher.group(1));
- assertTrue("Java Runtime version match", matches);
-
- String newJava9Version = "9-ea+19";
- Version newJava9 = Version.decode(newJava9Version);
- String newJava9Formatted = newJava9.toString();
- System.out.format("Potential new Java version: %1$s, parsed and
formatted: %2$s%n",
- newJava9Version, newJava9Formatted);
- assertEquals("new Java 9 version", "9.0.0_00-ea+19",
newJava9Formatted);
-
- String newJava10Version = "10+-ea";
- Version newJava10 = Version.decode(newJava10Version);
- String newJava10Formatted = newJava10.toString();
- System.out.format("Potential new Java 10 version: %1$s, parsed and
formatted: %2$s%n",
- newJava10Version, newJava10Formatted);
- assertEquals("new Java 10 version", "10.0.0_00--ea",
newJava10Formatted);
- }
-
- /**
- * Complete test of the new version strings possible with Java 9
- * (taken from <a
href="http://openjdk.java.net/jeps/223">http://openjdk.java.net/jeps/223</a>).
- */
- @Test
- public void testJava9Versions() {
- String[] versions = {
- "9-ea+19",
- "9+100",
- "9.0.1+20",
- "9.0.2+12",
- "9.1.2+62",
- "9.1.3+15",
- "9.1.4+8",
- "9.2.4+45",
- "7.4.10+11",
- "7.4.11+15",
- "7.5.11+43",
- "7.5.12+18",
- "7.5.13+13",
- "7.5.14+13",
- "7.6.14+19",
- "7.6.15+20",
- "9-ea",
- "9-ea+73",
- "9+100",
- "9",
- "9.1.2",
- "9.1.2+62",
- "9.0.1",
- "9.0.1+20"
- };
-
- // Just make sure we don't throw or get other errors decoding all these
- for (String version : versions) {
- Version v = Version.decode(version);
- System.out.format("Raw %1$s -> %2$s%n", version, v.toString());
- }
- }
-
- /**
- * Test the new {@link Version#safelyDecode}.
- */
- @Test
- public void testSafelyDecode() {
- try {
- Version junk = Version.safelyDecode("this is junk");
- assertEquals("safely decode default", EMPTY, junk);
- } catch (Exception ex) {
- fail("safelyDecode threw an exception: " + ex.getMessage());
- }
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+import org.apache.pivot.util.Version;
+
+
+/**
+ * Tests of the {@link Version} class.
+ */
+public class VersionTest {
+ /**
+ * Test version decode that happens at application startup.
+ */
+ @Test
+ public void testApplicationStartup() {
+ // These are the things that happen right away for ApplicationContext
+ // and therefore would break immediately if Version was broken (as did
+ // happen for Java 8u131).
+ // Get the JVM version
+ Version jvmVersion =
Version.decode(System.getProperty("java.vm.version"));
+ System.out.format("JVM Version: %1$s%n", jvmVersion.toString());
+ Version pivotVersion = null;
+ Package corePackage = Version.class.getPackage();
+
+ // Get the Java runtime version
+ Version javaVersion =
Version.decode(System.getProperty("java.version"));
+ System.out.format("Java version: %1$s%n", javaVersion);
+
+ // Get the Pivot version
+ String version = corePackage.getImplementationVersion();
+ if (version == null) {
+ pivotVersion = new Version(0, 0, 0, 0);
+ assertEquals("default Pivot version", "0.0.0_00",
pivotVersion.toString());
+ } else {
+ pivotVersion = Version.decode(version);
+ System.out.format("Pivot Version: %1$s%n", pivotVersion);
+ }
+ }
+
+ /** The Java version string that broke the old code (build overflows a
byte). */
+ private static final String S1_8_131 = "1.8.0_131";
+ /** Decoding that breaking version string. */
+ private static final Version V1 = Version.decode(S1_8_131);
+ /** The version object that should match that decoded value. */
+ private static final Version V8_131 = new Version(1, 8, 0, 131);
+ /** A version 1.0 string. */
+ private static final String S1_0_0 = "1.0.0_00";
+ /** Decoding version 1. */
+ private static final Version V0 = Version.decode(S1_0_0);
+ /** The version object that should match version 1. */
+ private static final Version V1_0 = new Version(1, 0, 0, 0);
+ /** The null/empty version object. */
+ private static final Version EMPTY = new Version(0, 0, 0, 0);
+
+ /**
+ * Test basic parsing (including our overflow fail case).
+ */
+ @Test
+ public void testVersionParsing() {
+ assertEquals("version decode", V8_131, V1);
+ assertEquals("version to string", V8_131.toString(), S1_8_131);
+
+ assertEquals("version 0 decode", V1_0, V0);
+ assertEquals("version 0 to string", S1_0_0, V1_0.toString());
+
+ // New Java 9 version number scheme
+ String j9 = "9.0.1+11";
+ Version vj9 = Version.decode(j9);
+ Version vj90 = new Version(9, 0, 1, 0);
+ assertEquals("Java version 9 decode", vj90, vj9);
+ assertEquals("Java version 9 to string", "9.0.1_00-11",
vj9.toString());
+ }
+
+ /**
+ * Test overflows of the new short values.
+ */
+ @Test
+ public void testLimits() {
+ Version vMax = new Version(32767, 32767, 32767, 32767);
+ String sMax = "32767.32767.32767_32767";
+ assertEquals("max versions", sMax, vMax.toString());
+ IllegalArgumentException argFailure = null;
+ try {
+ Version vOverflow = new Version(32768, 0, 1, 0);
+ } catch (IllegalArgumentException iae) {
+ argFailure = iae;
+ }
+ assertNotNull("illegal argument exception", argFailure);
+ assertEquals("exception message",
+ "majorVersion must be less than or equal 32767.",
+ argFailure.getMessage());
+ }
+
+ /**
+ * Test {@link Version#getNumber}.
+ */
+ @Test
+ public void testNumber() {
+ Version vNum = new Version(2, 1, 1, 100);
+ long num = vNum.getNumber();
+ System.out.format("test getNumber(): %1$s -> %2$d (0x%2$016x)%n",
vNum, num);
+ assertEquals("long number", 0x0002000100010064L, num);
+ }
+
+ /** Taken from PIVOT-996 test case -- the build suffix ... */
+ private static final String PIVOT_996_SUFFIX = "25.51-b14";
+ /** PIVOT-996 complete input string. */
+ private static final String PIVOT_996_INPUT = "8.1.028 " +
PIVOT_996_SUFFIX;
+ /** What we expect from PIVOT-996 test case on output. */
+ private static final String PIVOT_996_OUTPUT = "8.1.28_00-" +
PIVOT_996_SUFFIX;
+
+ /**
+ * Other test cases (from issues, or other sources).
+ */
+ @Test
+ public void testOtherVersions() {
+ Version jvmVersionParsed = Version.decode(PIVOT_996_INPUT);
+ Version jvmVersionExplicit = new Version(8, 1, 28, 0,
PIVOT_996_SUFFIX);
+ String parsedToString = jvmVersionParsed.toString();
+
+ System.out.println("Information only: our version = " +
Version.implementationVersion());
+
+ assertEquals("PIVOT-996 test case", jvmVersionExplicit,
jvmVersionParsed);
+ System.out.format("PIVOT-996 parsed/toString: %1$s, expected: %2$s%n",
+ parsedToString, PIVOT_996_OUTPUT);
+ assertEquals("PIVOT-996 toString", PIVOT_996_OUTPUT, parsedToString);
+
+ Pattern versionPattern = Pattern.compile("(\\d+(\\.\\d+\\.\\d+)?).*");
+ String sysJavaVersion = System.getProperty("java.runtime.version");
+ Version javaVersion = Version.decode(sysJavaVersion);
+ String formattedJavaVersion = javaVersion.toString();
+ String simpleVersion = javaVersion.simpleToString();
+ System.out.format("Java Runtime version (parsed and formatted): %1$s,
raw: %2$s, simple: %3$s%n",
+ formattedJavaVersion, sysJavaVersion, simpleVersion);
+ Matcher sysMatcher = versionPattern.matcher(sysJavaVersion);
+ boolean matches = sysMatcher.matches()
+ && simpleVersion.startsWith(sysMatcher.group(1));
+ assertTrue("Java Runtime version match", matches);
+
+ String newJava9Version = "9-ea+19";
+ Version newJava9 = Version.decode(newJava9Version);
+ String newJava9Formatted = newJava9.toString();
+ System.out.format("Potential new Java version: %1$s, parsed and
formatted: %2$s%n",
+ newJava9Version, newJava9Formatted);
+ assertEquals("new Java 9 version", "9.0.0_00-ea+19",
newJava9Formatted);
+
+ String newJava10Version = "10+-ea";
+ Version newJava10 = Version.decode(newJava10Version);
+ String newJava10Formatted = newJava10.toString();
+ System.out.format("Potential new Java 10 version: %1$s, parsed and
formatted: %2$s%n",
+ newJava10Version, newJava10Formatted);
+ assertEquals("new Java 10 version", "10.0.0_00--ea",
newJava10Formatted);
+ }
+
+ /**
+ * Complete test of the new version strings possible with Java 9
+ * (taken from <a
href="http://openjdk.java.net/jeps/223">http://openjdk.java.net/jeps/223</a>).
+ */
+ @Test
+ public void testJava9Versions() {
+ String[] versions = {
+ "9-ea+19",
+ "9+100",
+ "9.0.1+20",
+ "9.0.2+12",
+ "9.1.2+62",
+ "9.1.3+15",
+ "9.1.4+8",
+ "9.2.4+45",
+ "7.4.10+11",
+ "7.4.11+15",
+ "7.5.11+43",
+ "7.5.12+18",
+ "7.5.13+13",
+ "7.5.14+13",
+ "7.6.14+19",
+ "7.6.15+20",
+ "9-ea",
+ "9-ea+73",
+ "9+100",
+ "9",
+ "9.1.2",
+ "9.1.2+62",
+ "9.0.1",
+ "9.0.1+20"
+ };
+
+ // Just make sure we don't throw or get other errors decoding all these
+ for (String version : versions) {
+ Version v = Version.decode(version);
+ System.out.format("Raw %1$s -> %2$s%n", version, v.toString());
+ }
+ }
+
+ /**
+ * Test the new {@link Version#safelyDecode}.
+ */
+ @Test
+ public void testSafelyDecode() {
+ try {
+ Version junk = Version.safelyDecode("this is junk");
+ assertEquals("safely decode default", EMPTY, junk);
+ } catch (Exception ex) {
+ fail("safelyDecode threw an exception: " + ex.getMessage());
+ }
+ }
+}
+
Propchange: pivot/trunk/core/test/org/apache/pivot/util/test/VersionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java
(original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java Tue
Oct 31 19:15:47 2023
@@ -1,59 +1,59 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pivot.util.test;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Iterator;
-import org.junit.Test;
-
-import org.apache.pivot.collections.ArrayList;
-import org.apache.pivot.util.Vote;
-import org.apache.pivot.util.VoteResult;
-
-
-/**
- * Tests of the {@link VoteResult} class; used for tabulating votes
- * inside of lambda functions.
- */
-public class VoteResultTest {
- /**
- * Run the basic tests.
- */
- @Test
- public void test1() {
- ArrayList<Vote> votes = new ArrayList<>();
- votes.add(Vote.APPROVE);
- votes.add(Vote.DEFER);
- votes.add(Vote.DENY);
-
- // These are the expected results as each vote is tallied
- ArrayList<Vote> results = new ArrayList<>();
- results.add(Vote.APPROVE);
- results.add(Vote.DEFER);
- results.add(Vote.DENY);
-
- VoteResult result = new VoteResult();
- Iterator<Vote> resultIter = results.iterator();
-
- for (Vote vote : votes) {
- result.tally(vote);
- assertEquals(result.get(), resultIter.next());
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Iterator;
+import org.junit.Test;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.util.Vote;
+import org.apache.pivot.util.VoteResult;
+
+
+/**
+ * Tests of the {@link VoteResult} class; used for tabulating votes
+ * inside of lambda functions.
+ */
+public class VoteResultTest {
+ /**
+ * Run the basic tests.
+ */
+ @Test
+ public void test1() {
+ ArrayList<Vote> votes = new ArrayList<>();
+ votes.add(Vote.APPROVE);
+ votes.add(Vote.DEFER);
+ votes.add(Vote.DENY);
+
+ // These are the expected results as each vote is tallied
+ ArrayList<Vote> results = new ArrayList<>();
+ results.add(Vote.APPROVE);
+ results.add(Vote.DEFER);
+ results.add(Vote.DENY);
+
+ VoteResult result = new VoteResult();
+ Iterator<Vote> resultIter = results.iterator();
+
+ for (Vote vote : votes) {
+ result.tally(vote);
+ assertEquals(result.get(), resultIter.next());
+ }
+ }
+
+}
Propchange: pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java
------------------------------------------------------------------------------
svn:eol-style = native