diff options
author | Brian Vosburgh | 2015-11-16 15:32:18 +0000 |
---|---|---|
committer | Brian Vosburgh | 2015-11-16 15:32:18 +0000 |
commit | 554e62225689a82a3e5850d778d55fbe71fd93cd (patch) | |
tree | 00dac8791282697b43024b538fb8982731479e87 /common | |
parent | b6a91bf0fb7e55df46e116de2abde852d056c89b (diff) | |
download | webtools.dali-554e62225689a82a3e5850d778d55fbe71fd93cd.tar.gz webtools.dali-554e62225689a82a3e5850d778d55fbe71fd93cd.tar.xz webtools.dali-554e62225689a82a3e5850d778d55fbe71fd93cd.zip |
improve Reference test coverage
Diffstat (limited to 'common')
20 files changed, 1262 insertions, 700 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/AbstractModifiableBooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/AbstractModifiableBooleanReference.java index 61a2af97bb..4da8290ff5 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/AbstractModifiableBooleanReference.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/AbstractModifiableBooleanReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Oracle. All rights reserved. + * Copyright (c) 2012, 2015 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -27,7 +27,27 @@ public abstract class AbstractModifiableBooleanReference } public boolean flip() { - return this.setValue( ! this.getValue()); + boolean v = ! this.getValue(); + this.setValue(v); + return v; + } + + public boolean and(boolean b) { + boolean v = this.getValue() && b; + this.setValue(v); + return v; + } + + public boolean or(boolean b) { + boolean v = this.getValue() || b; + this.setValue(v); + return v; + } + + public boolean xor(boolean b) { + boolean v = this.getValue() ^ b; + this.setValue(v); + return v; } public boolean setNot(boolean value) { @@ -41,4 +61,25 @@ public abstract class AbstractModifiableBooleanReference public boolean setFalse() { return this.setValue(false); } + + public boolean commit(boolean newValue, boolean expectedValue) { + if (this.getValue() == expectedValue) { + this.setValue(newValue); + return true; + } + return false; + } + + public boolean swap(ModifiableBooleanReference other) { + if (other == this) { + return this.getValue(); + } + boolean thisValue = this.getValue(); + boolean otherValue = other.getValue(); + if (thisValue != otherValue) { + other.setValue(thisValue); + this.setValue(otherValue); + } + return otherValue; + } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/LazyObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/LazyObjectReference.java index 96b54d676a..28fcaf88be 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/LazyObjectReference.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/LazyObjectReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Oracle. All rights reserved. + * Copyright (c) 2010, 2015 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,8 +10,7 @@ package org.eclipse.jpt.common.utility.internal.reference; import java.io.Serializable; -import org.eclipse.jpt.common.utility.internal.ObjectTools; -import org.eclipse.jpt.common.utility.reference.ObjectReference; +import org.eclipse.jpt.common.utility.factory.Factory; /** * Provide a thread-safe, reasonably performing container for holding an @@ -29,28 +28,26 @@ import org.eclipse.jpt.common.utility.reference.ObjectReference; * @see SimpleObjectReference * @see SynchronizedObject */ -public abstract class LazyObjectReference<V> - implements ObjectReference<V>, Cloneable, Serializable +public final class LazyObjectReference<V> + extends AbstractObjectReference<V> + implements Cloneable, Serializable { - /** Backing value. */ private volatile V value = null; - private static final long serialVersionUID = 1L; + private final Factory<V> factory; + private static final long serialVersionUID = 1L; - // ********** constructors ********** /** * Create a lazy object reference. */ - protected LazyObjectReference() { + public LazyObjectReference(Factory<V> factory) { super(); + this.factory = factory; } - - // ********** value ********** - - /** + /* * In JDK 5 and later, this "double-checked locking" idiom works as long * as the instance variable is marked <code>volatile</code>. */ @@ -60,34 +57,13 @@ public abstract class LazyObjectReference<V> synchronized (this) { result = this.value; if (result == null) { - this.value = result = this.buildValue(); + result = this.value = this.factory.create(); } } } return result; } - protected abstract V buildValue(); - - public boolean valueEquals(Object object) { - return ObjectTools.equals(this.getValue(), object); - } - - public boolean valueNotEqual(Object object) { - return ObjectTools.notEquals(this.getValue(), object); - } - - public boolean isNull() { - return this.getValue() == null; - } - - public boolean isNotNull() { - return this.getValue() != null; - } - - - // ********** standard methods ********** - @Override public LazyObjectReference<V> clone() { try { @@ -98,12 +74,4 @@ public abstract class LazyObjectReference<V> throw new InternalError(); } } - - /** - * This method will <em>not</em> trigger the "lazy-initialization". - */ - @Override - public String toString() { - return '[' + String.valueOf(this.value) + ']'; - } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleBooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleBooleanReference.java index 0d935a2587..1ee242a8b7 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleBooleanReference.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleBooleanReference.java @@ -45,7 +45,7 @@ public class SimpleBooleanReference } - // ********** accessors ********** + // ********** BooleanReference ********** public boolean getValue() { return this.value; @@ -67,6 +67,9 @@ public class SimpleBooleanReference return ! this.value; } + + // ********** ModifiableBooleanReference ********** + public boolean setValue(boolean value) { boolean old = this.value; this.value = value; diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleObjectReference.java index 01d346330c..8c8b862501 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleObjectReference.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/reference/SimpleObjectReference.java @@ -101,7 +101,7 @@ public class SimpleObjectReference<V> public boolean commit(V newValue, V expectedValue) { if (ObjectTools.equals(this.value, expectedValue)) { - this.value = newValue; + this.setValue(newValue); return true; } return false; @@ -116,7 +116,7 @@ public class SimpleObjectReference<V> return this.value; } other.setValue(this.value); - this.value = otherValue; + this.setValue(otherValue); return otherValue; } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractBooleanReferenceTests.java index 92233241f6..833943f678 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractBooleanReferenceTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractBooleanReferenceTests.java @@ -11,81 +11,29 @@ package org.eclipse.jpt.common.utility.tests.internal.reference; import org.eclipse.jpt.common.utility.internal.reference.AbstractBooleanReference; import org.eclipse.jpt.common.utility.reference.BooleanReference; -import junit.framework.TestCase; -@SuppressWarnings("nls") public class AbstractBooleanReferenceTests - extends TestCase + extends BooleanReferenceTests { public AbstractBooleanReferenceTests(String name) { super(name); } - public void testGetValue() { - LocalBooleanReference br = new LocalBooleanReference(); - assertTrue(br.getValue()); - } - - public void testIs() { - LocalBooleanReference br = new LocalBooleanReference(); - assertTrue(br.is(true)); - assertFalse(br.is(false)); - } - - public void testIsNot() { - LocalBooleanReference br = new LocalBooleanReference(); - assertFalse(br.isNot(true)); - assertTrue(br.isNot(false)); - } - - public void testIsTrue() { - LocalBooleanReference br = new LocalBooleanReference(); - assertTrue(br.isTrue()); - } - - public void testIsFalse() { - BooleanReference br = new LocalBooleanReference(); - assertFalse(br.isFalse()); - br = new FalseLocalBooleanReference(); - assertTrue(br.isFalse()); - } - - public void testEquals() { - LocalBooleanReference br1 = new LocalBooleanReference(); - LocalBooleanReference br2 = new LocalBooleanReference(); - assertTrue(br1.equals(br1)); - assertFalse(br1.equals(br2)); - } - - public void testHashCode() { - LocalBooleanReference br = new LocalBooleanReference(); - assertEquals(br.hashCode(), br.hashCode()); - } - - public void testToString() { - LocalBooleanReference br = new LocalBooleanReference(); - assertEquals("[true]", br.toString()); + @Override + protected BooleanReference buildBooleanReference(boolean value) { + return new LocalBooleanReference(value); } private class LocalBooleanReference extends AbstractBooleanReference { - LocalBooleanReference() { - super(); - } - public boolean getValue() { - return true; - } - } - - private class FalseLocalBooleanReference - extends AbstractBooleanReference - { - FalseLocalBooleanReference() { + private final boolean value; + LocalBooleanReference(boolean value) { super(); + this.value = value; } public boolean getValue() { - return false; + return this.value; } } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractIntReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractIntReferenceTests.java index 3e48ef12e7..d148c4bc7b 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractIntReferenceTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractIntReferenceTests.java @@ -9,155 +9,25 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.reference; -import org.eclipse.jpt.common.utility.internal.predicate.int_.IntPredicateTools; import org.eclipse.jpt.common.utility.internal.reference.AbstractIntReference; -import org.eclipse.jpt.common.utility.internal.reference.SimpleIntReference; -import junit.framework.TestCase; +import org.eclipse.jpt.common.utility.reference.IntReference; -@SuppressWarnings("nls") public class AbstractIntReferenceTests - extends TestCase + extends IntReferenceTests { public AbstractIntReferenceTests(String name) { super(name); } - public void testGetValue() { - LocalIntReference br = new LocalIntReference(42); - assertEquals(42, br.getValue()); - } - - public void testEqualsInt() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.equals(42)); - assertFalse(br.equals(0)); - } - - public void testNotEqual() { - LocalIntReference br = new LocalIntReference(42); - assertFalse(br.notEqual(42)); - assertTrue(br.notEqual(0)); - } - - public void testIsZero() { - LocalIntReference br = new LocalIntReference(42); - assertFalse(br.isZero()); - br = new LocalIntReference(0); - assertTrue(br.isZero()); - } - - public void testIsNotZero() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isNotZero()); - br = new LocalIntReference(0); - assertFalse(br.isNotZero()); - } - - public void testIsGreaterThan() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isGreaterThan(22)); - assertFalse(br.isGreaterThan(2222)); - } - - public void testIsGreaterThanOrEqual() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isGreaterThanOrEqual(22)); - assertTrue(br.isGreaterThanOrEqual(42)); - assertFalse(br.isGreaterThanOrEqual(2222)); - } - - public void testIsLessThan() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isLessThan(2222)); - assertFalse(br.isLessThan(22)); - } - - public void testIsLessThanOrEqual() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isLessThanOrEqual(2222)); - assertTrue(br.isLessThanOrEqual(42)); - assertFalse(br.isLessThanOrEqual(22)); - } - - public void testIsPositive() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isPositive()); - br = new LocalIntReference(0); - assertFalse(br.isPositive()); - br = new LocalIntReference(-42); - assertFalse(br.isPositive()); - } - - public void testIsNotPositive() { - LocalIntReference br = new LocalIntReference(-42); - assertTrue(br.isNotPositive()); - br = new LocalIntReference(0); - assertTrue(br.isNotPositive()); - br = new LocalIntReference(42); - assertFalse(br.isNotPositive()); - } - - public void testIsNegative() { - LocalIntReference br = new LocalIntReference(-42); - assertTrue(br.isNegative()); - br = new LocalIntReference(0); - assertFalse(br.isNegative()); - br = new LocalIntReference(42); - assertFalse(br.isNegative()); - } - - public void testIsNotNegative() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isNotNegative()); - br = new LocalIntReference(0); - assertTrue(br.isNotNegative()); - br = new LocalIntReference(-42); - assertFalse(br.isNotNegative()); - } - - public void testIsMemberOf() { - LocalIntReference br = new LocalIntReference(42); - assertTrue(br.isMemberOf(IntPredicateTools.isEven())); - assertFalse(br.isMemberOf(IntPredicateTools.isOdd())); - } - - public void testIsNotMemberOf() { - LocalIntReference br = new LocalIntReference(42); - assertFalse(br.isNotMemberOf(IntPredicateTools.isEven())); - assertTrue(br.isNotMemberOf(IntPredicateTools.isOdd())); - } - - public void testCompareToIntReference() { - LocalIntReference ir1 = new LocalIntReference(44); - SimpleIntReference ir2 = new SimpleIntReference(44); - assertTrue(ir1.compareTo(ir2) == 0); - ir2 = new SimpleIntReference(55); - assertTrue(ir1.compareTo(ir2) < 0); - ir2 = new SimpleIntReference(33); - assertTrue(ir1.compareTo(ir2) > 0); - } - - public void testEquals() { - LocalIntReference br1 = new LocalIntReference(42); - LocalIntReference br2 = new LocalIntReference(42); - assertTrue(br1.equals(br1)); - assertFalse(br1.equals(br2)); - } - - public void testHashCode() { - LocalIntReference br = new LocalIntReference(42); - assertEquals(br.hashCode(), br.hashCode()); - } - - public void testToString() { - LocalIntReference br = new LocalIntReference(42); - assertEquals("[42]", br.toString()); + @Override + protected IntReference buildIntReference(int value) { + return new LocalIntReference(value); } private class LocalIntReference extends AbstractIntReference { - private int value; + private final int value; LocalIntReference(int value) { super(); this.value = value; diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableBooleanReferenceTests.java new file mode 100644 index 0000000000..fc63de5339 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableBooleanReferenceTests.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.reference.AbstractModifiableBooleanReference; +import org.eclipse.jpt.common.utility.reference.ModifiableBooleanReference; + +public class AbstractModifiableBooleanReferenceTests + extends ModifiableBooleanReferenceTests +{ + public AbstractModifiableBooleanReferenceTests(String name) { + super(name); + } + + @Override + protected ModifiableBooleanReference buildBooleanReference(boolean value) { + return new LocalBooleanReference(value); + } + + private class LocalBooleanReference + extends AbstractModifiableBooleanReference + { + private boolean value; + LocalBooleanReference(boolean value) { + super(); + this.value = value; + } + public boolean getValue() { + return this.value; + } + + public boolean setValue(boolean value) { + boolean old = this.value; + this.value = value; + return old; + } + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableIntReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableIntReferenceTests.java new file mode 100644 index 0000000000..f382e026d4 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/AbstractModifiableIntReferenceTests.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.reference.AbstractModifiableIntReference; +import org.eclipse.jpt.common.utility.reference.ModifiableIntReference; + +public class AbstractModifiableIntReferenceTests + extends ModifiableIntReferenceTests +{ + public AbstractModifiableIntReferenceTests(String name) { + super(name); + } + + @Override + protected ModifiableIntReference buildIntReference(int value) { + return new LocalIntReference(value); + } + + private class LocalIntReference + extends AbstractModifiableIntReference + { + private int value; + LocalIntReference(int value) { + super(); + this.value = value; + } + public int getValue() { + return this.value; + } + public int setValue(int value) { + int old = this.value; + this.value = value; + return old; + } + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/BooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/BooleanReferenceTests.java new file mode 100644 index 0000000000..9e16503a0e --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/BooleanReferenceTests.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.reference.BooleanReference; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public abstract class BooleanReferenceTests + extends TestCase +{ + public BooleanReferenceTests(String name) { + super(name); + } + + protected BooleanReference buildBooleanReference() { + return this.buildBooleanReference(true); + } + + protected abstract BooleanReference buildBooleanReference(boolean value); + + public void testGetValue() { + BooleanReference br = this.buildBooleanReference(); + assertTrue(br.getValue()); + } + + public void testIs() { + BooleanReference br = this.buildBooleanReference(); + assertTrue(br.is(true)); + assertFalse(br.is(false)); + } + + public void testIsNot() { + BooleanReference br = this.buildBooleanReference(); + assertFalse(br.isNot(true)); + assertTrue(br.isNot(false)); + } + + public void testIsTrue() { + BooleanReference br = this.buildBooleanReference(); + assertTrue(br.isTrue()); + } + + public void testIsFalse() { + BooleanReference br = this.buildBooleanReference(); + assertFalse(br.isFalse()); + br = this.buildBooleanReference(false); + assertTrue(br.isFalse()); + } + + public void testEquals() { + BooleanReference br1 = this.buildBooleanReference(); + BooleanReference br2 = this.buildBooleanReference(); + assertTrue(br1.equals(br1)); + assertFalse(br1.equals(br2)); + } + + public void testHashCode() { + BooleanReference br = this.buildBooleanReference(); + assertEquals(br.hashCode(), br.hashCode()); + } + + public void testToString() { + BooleanReference br = this.buildBooleanReference(true); + assertEquals("[true]", br.toString()); + br = this.buildBooleanReference(false); + assertEquals("[false]", br.toString()); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FalseBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FalseBooleanReferenceTests.java new file mode 100644 index 0000000000..5f195f1bc4 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FalseBooleanReferenceTests.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.reference.FalseBooleanReference; +import org.eclipse.jpt.common.utility.reference.BooleanReference; +import org.eclipse.jpt.common.utility.tests.internal.TestTools; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public class FalseBooleanReferenceTests + extends TestCase +{ + public FalseBooleanReferenceTests(String name) { + super(name); + } + + public void testGetValue() { + BooleanReference ref = FalseBooleanReference.instance(); + assertFalse(ref.getValue()); + } + + public void testIs() { + BooleanReference ref = FalseBooleanReference.instance(); + assertFalse(ref.is(true)); + assertTrue(ref.is(false)); + } + + public void testIsNot() { + BooleanReference ref = FalseBooleanReference.instance(); + assertTrue(ref.isNot(true)); + assertFalse(ref.isNot(false)); + } + + public void testIsTrue() { + BooleanReference ref = FalseBooleanReference.instance(); + assertFalse(ref.isTrue()); + } + + public void testIsFalse() { + BooleanReference ref = FalseBooleanReference.instance(); + assertTrue(ref.isFalse()); + } + + public void testToString() { + BooleanReference ref = FalseBooleanReference.instance(); + assertEquals("[false]", ref.toString()); + } + + public void testSerialization() throws Exception { + BooleanReference ref = FalseBooleanReference.instance(); + assertSame(ref, TestTools.serialize(ref)); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FlaggedObjectReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FlaggedObjectReferenceTests.java new file mode 100644 index 0000000000..fe26b0a762 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/FlaggedObjectReferenceTests.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.reference.FlaggedObjectReference; +import org.eclipse.jpt.common.utility.reference.ObjectReference; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public class FlaggedObjectReferenceTests + extends TestCase +{ + public FlaggedObjectReferenceTests(String name) { + super(name); + } + + public void testConstructors() { + ObjectReference<String> ref = new FlaggedObjectReference<>(); + assertNull(ref.getValue()); + ref = new FlaggedObjectReference<>("foo"); + assertEquals("foo", ref.getValue()); + } + + public void testIsSet() { + FlaggedObjectReference<String> ref = new FlaggedObjectReference<>(); + assertNull(ref.getValue()); + assertFalse(ref.isSet()); + ref.setValue(null); + assertNull(ref.getValue()); + assertTrue(ref.isSet()); + + ref = new FlaggedObjectReference<>("foo"); + assertEquals("foo", ref.getValue()); + assertFalse(ref.isSet()); + ref.setValue(null); + assertNull(ref.getValue()); + assertTrue(ref.isSet()); + + ref = new FlaggedObjectReference<>("foo"); + assertEquals("foo", ref.getValue()); + assertFalse(ref.isSet()); + ref.setValue("foo"); + assertEquals("foo", ref.getValue()); + assertTrue(ref.isSet()); + } + + public void testToString() { + FlaggedObjectReference<String> ref = new FlaggedObjectReference<>(); + assertNull(ref.getValue()); + assertEquals("[null]", ref.toString()); + ref.setValue(null); + assertEquals("*[null]", ref.toString()); + + ref = new FlaggedObjectReference<>("foo"); + assertEquals("foo", ref.getValue()); + assertEquals("[foo]", ref.toString()); + ref.setValue(null); + assertEquals("*[null]", ref.toString()); + + ref = new FlaggedObjectReference<>("foo"); + assertEquals("foo", ref.getValue()); + assertEquals("[foo]", ref.toString()); + ref.setValue("foo"); + assertEquals("*[foo]", ref.toString()); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/IntReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/IntReferenceTests.java new file mode 100644 index 0000000000..5221675789 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/IntReferenceTests.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.predicate.int_.IntPredicateTools; +import org.eclipse.jpt.common.utility.internal.reference.SimpleIntReference; +import org.eclipse.jpt.common.utility.reference.IntReference; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public abstract class IntReferenceTests + extends TestCase +{ + public IntReferenceTests(String name) { + super(name); + } + + protected IntReference buildIntReference() { + return this.buildIntReference(0); + } + + protected abstract IntReference buildIntReference(int value); + + public void testGetValue() { + IntReference ref = this.buildIntReference(42); + assertEquals(42, ref.getValue()); + } + + public void testEqualsInt() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.equals(42)); + assertFalse(ref.equals(0)); + } + + public void testNotEqualInt() { + IntReference ref = this.buildIntReference(42); + assertFalse(ref.notEqual(42)); + assertTrue(ref.notEqual(0)); + } + + public void testIsZero() { + IntReference ref = this.buildIntReference(42); + assertFalse(ref.isZero()); + ref = this.buildIntReference(0); + assertTrue(ref.isZero()); + } + + public void testIsNotZero() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isNotZero()); + ref = this.buildIntReference(0); + assertFalse(ref.isNotZero()); + } + + public void testIsGreaterThan() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isGreaterThan(22)); + assertFalse(ref.isGreaterThan(2222)); + } + + public void testIsGreaterThanOrEqual() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isGreaterThanOrEqual(22)); + assertTrue(ref.isGreaterThanOrEqual(42)); + assertFalse(ref.isGreaterThanOrEqual(2222)); + } + + public void testIsLessThan() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isLessThan(2222)); + assertFalse(ref.isLessThan(22)); + } + + public void testIsLessThanOrEqual() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isLessThanOrEqual(2222)); + assertTrue(ref.isLessThanOrEqual(42)); + assertFalse(ref.isLessThanOrEqual(22)); + } + + public void testIsPositive() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isPositive()); + ref = this.buildIntReference(0); + assertFalse(ref.isPositive()); + ref = this.buildIntReference(-42); + assertFalse(ref.isPositive()); + } + + public void testIsNotPositive() { + IntReference ref = this.buildIntReference(-42); + assertTrue(ref.isNotPositive()); + ref = this.buildIntReference(0); + assertTrue(ref.isNotPositive()); + ref = this.buildIntReference(42); + assertFalse(ref.isNotPositive()); + } + + public void testIsNegative() { + IntReference ref = this.buildIntReference(-42); + assertTrue(ref.isNegative()); + ref = this.buildIntReference(0); + assertFalse(ref.isNegative()); + ref = this.buildIntReference(42); + assertFalse(ref.isNegative()); + } + + public void testIsNotNegative() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isNotNegative()); + ref = this.buildIntReference(0); + assertTrue(ref.isNotNegative()); + ref = this.buildIntReference(-42); + assertFalse(ref.isNotNegative()); + } + + public void testIsMemberOf() { + IntReference ref = this.buildIntReference(42); + assertTrue(ref.isMemberOf(IntPredicateTools.isEven())); + assertFalse(ref.isMemberOf(IntPredicateTools.isOdd())); + } + + public void testIsNotMemberOf() { + IntReference ref = this.buildIntReference(42); + assertFalse(ref.isNotMemberOf(IntPredicateTools.isEven())); + assertTrue(ref.isNotMemberOf(IntPredicateTools.isOdd())); + } + + public void testCompareToIntReference() { + IntReference ref1 = this.buildIntReference(44); + SimpleIntReference ref2 = new SimpleIntReference(44); + assertTrue(ref1.compareTo(ref2) == 0); + ref2 = new SimpleIntReference(55); + assertTrue(ref1.compareTo(ref2) < 0); + ref2 = new SimpleIntReference(33); + assertTrue(ref1.compareTo(ref2) > 0); + } + + public void testEquals() { + IntReference ref1 = this.buildIntReference(42); + IntReference ref2 = this.buildIntReference(42); + assertTrue(ref1.equals(ref1)); + assertFalse(ref1.equals(ref2)); + } + + public void testHashCode() { + IntReference ref = this.buildIntReference(42); + assertEquals(ref.hashCode(), ref.hashCode()); + } + + public void testToString() { + IntReference ref = this.buildIntReference(42); + assertEquals("[42]", ref.toString()); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/JptCommonUtilityReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/JptCommonUtilityReferenceTests.java index 0440070901..c6d055f0f7 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/JptCommonUtilityReferenceTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/JptCommonUtilityReferenceTests.java @@ -22,14 +22,21 @@ public class JptCommonUtilityReferenceTests { suite.addTestSuite(AbstractBooleanReferenceTests.class); suite.addTestSuite(AbstractIntReferenceTests.class); + suite.addTestSuite(AbstractModifiableBooleanReferenceTests.class); + suite.addTestSuite(AbstractModifiableIntReferenceTests.class); suite.addTestSuite(AbstractModifiableObjectReferenceTests.class); suite.addTestSuite(AbstractObjectReferenceTests.class); + suite.addTestSuite(FalseBooleanReferenceTests.class); + suite.addTestSuite(FlaggedObjectReferenceTests.class); + suite.addTestSuite(LazyObjectReferenceTests.class); + suite.addTestSuite(ReferenceToolsTests.class); suite.addTestSuite(SimpleBooleanReferenceTests.class); suite.addTestSuite(SimpleIntReferenceTests.class); suite.addTestSuite(SimpleObjectReferenceTests.class); suite.addTestSuite(SynchronizedBooleanTests.class); suite.addTestSuite(SynchronizedIntTests.class); suite.addTestSuite(SynchronizedObjectTests.class); + suite.addTestSuite(TrueBooleanReferenceTests.class); return suite; } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/LazyObjectReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/LazyObjectReferenceTests.java new file mode 100644 index 0000000000..24b2900477 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/LazyObjectReferenceTests.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.factory.Factory; +import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.factory.FactoryAdapter; +import org.eclipse.jpt.common.utility.internal.reference.LazyObjectReference; +import org.eclipse.jpt.common.utility.reference.ObjectReference; + +@SuppressWarnings("nls") +public class LazyObjectReferenceTests + extends ObjectReferenceTests +{ + public LazyObjectReferenceTests(String name) { + super(name); + } + + @Override + protected ObjectReference<String> buildObjectReference(String value) { + return new LazyObjectReference<>(this.buildFactory(value)); + } + + private Factory<String> buildFactory(String value) { + return new LocalFactory(value); + } + + @Override + public void testGetValue() { + super.testGetValue(); + ObjectReference<String> ref = this.buildObjectReference(); + assertNull(ref.getValue()); + ref = this.buildObjectReference("foo"); + assertEquals("foo", ref.getValue()); + assertEquals("foo", ref.getValue()); + } + + public void testClone() { + ObjectReference<String> or = this.buildObjectReference("foo"); + @SuppressWarnings("unchecked") + ObjectReference<String> clone = (ObjectReference<String>) ObjectTools.execute(or, "clone"); + assertEquals("foo", clone.getValue()); + assertNotSame(or, clone); + } + + private static class LocalFactory + extends FactoryAdapter<String> + { + protected String value; + protected LocalFactory(String value) { + super(); + this.value = value; + } + @Override + public String create() { + return this.value; + } + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableBooleanReferenceTests.java new file mode 100644 index 0000000000..60677660ed --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableBooleanReferenceTests.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.reference.ModifiableBooleanReference; + +public abstract class ModifiableBooleanReferenceTests + extends BooleanReferenceTests +{ + public ModifiableBooleanReferenceTests(String name) { + super(name); + } + + @Override + protected ModifiableBooleanReference buildBooleanReference() { + return (ModifiableBooleanReference) super.buildBooleanReference(); + } + + @Override + protected abstract ModifiableBooleanReference buildBooleanReference(boolean value); + + public void testSetValue() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.getValue()); + br.setValue(false); + assertFalse(br.getValue()); + } + + public void testFlip() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.getValue()); + assertFalse(br.flip()); + assertFalse(br.getValue()); + assertTrue(br.flip()); + assertTrue(br.getValue()); + } + + public void testAnd() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.and(true)); + assertTrue(br.getValue()); + + assertFalse(br.and(false)); + assertFalse(br.getValue()); + + assertFalse(br.and(true)); + assertFalse(br.getValue()); + + assertFalse(br.and(false)); + assertFalse(br.getValue()); + } + + public void testOr() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.or(true)); + assertTrue(br.getValue()); + + assertTrue(br.or(false)); + assertTrue(br.getValue()); + + assertTrue(br.setValue(false)); + assertFalse(br.or(false)); + assertFalse(br.getValue()); + + assertTrue(br.or(true)); + assertTrue(br.getValue()); + } + + public void testXor() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertFalse(br.xor(true)); + assertFalse(br.getValue()); + + assertFalse(br.setValue(true)); + assertTrue(br.xor(false)); + assertTrue(br.getValue()); + + assertTrue(br.setValue(false)); + assertFalse(br.xor(false)); + assertFalse(br.getValue()); + + assertFalse(br.setValue(false)); + assertTrue(br.xor(true)); + assertTrue(br.getValue()); + } + + public void testSetNotBoolean() { + ModifiableBooleanReference br = this.buildBooleanReference(false); + assertFalse(br.getValue()); + br.setNot(true); + assertFalse(br.getValue()); + br.setNot(true); + assertFalse(br.getValue()); + br.setNot(false); + assertTrue(br.getValue()); + } + + public void testSetTrue() { + ModifiableBooleanReference br = this.buildBooleanReference(false); + assertFalse(br.getValue()); + br.setTrue(); + assertTrue(br.getValue()); + } + + public void testSetFalse() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.getValue()); + br.setFalse(); + assertFalse(br.getValue()); + } + + public void testCommit() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.commit(false, true)); + assertFalse(br.getValue()); + + assertFalse(br.commit(false, true)); + assertFalse(br.getValue()); + + assertTrue(br.commit(true, false)); + assertTrue(br.getValue()); + + assertFalse(br.commit(true, false)); + assertTrue(br.getValue()); + + assertFalse(br.commit(false, false)); + assertTrue(br.getValue()); + + assertTrue(br.setValue(false)); + assertFalse(br.commit(true, true)); + assertFalse(br.getValue()); + } + + public void testSwap_sameObject() { + ModifiableBooleanReference br = this.buildBooleanReference(true); + assertTrue(br.swap(br)); + assertTrue(br.getValue()); + } + + public void testSwap_sameValues() { + ModifiableBooleanReference br1 = this.buildBooleanReference(true); + ModifiableBooleanReference br2 = this.buildBooleanReference(true); + assertTrue(br1.swap(br2)); + assertTrue(br1.getValue()); + assertTrue(br2.getValue()); + } + + public void testSwap_differentValues1() { + ModifiableBooleanReference br1 = this.buildBooleanReference(true); + ModifiableBooleanReference br2 = this.buildBooleanReference(false); + assertFalse(br1.swap(br2)); + assertFalse(br1.getValue()); + assertTrue(br2.getValue()); + } + + public void testSwap_differentValues2() { + ModifiableBooleanReference br1 = this.buildBooleanReference(false); + ModifiableBooleanReference br2 = this.buildBooleanReference(true); + assertTrue(br1.swap(br2)); + assertTrue(br1.getValue()); + assertFalse(br2.getValue()); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableIntReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableIntReferenceTests.java new file mode 100644 index 0000000000..06bccff2a1 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ModifiableIntReferenceTests.java @@ -0,0 +1,367 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.reference.ModifiableIntReference; + +public abstract class ModifiableIntReferenceTests + extends IntReferenceTests +{ + public ModifiableIntReferenceTests(String name) { + super(name); + } + + @Override + protected ModifiableIntReference buildIntReference() { + return this.buildIntReference(0); + } + + @Override + protected abstract ModifiableIntReference buildIntReference(int value); + + public void testSetValueInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(-3); + assertEquals(-3, ref.getValue()); + assertEquals(-3, ref.setValue(4)); + assertEquals(4, ref.getValue()); + } + + public void testAbs() { + ModifiableIntReference ref; + ref = this.buildIntReference(-3); + assertEquals(-3, ref.getValue()); + assertEquals(3, ref.abs()); + assertEquals(3, ref.getValue()); + + ref.setValue(3); + assertEquals(3, ref.getValue()); + assertEquals(3, ref.abs()); + assertEquals(3, ref.getValue()); + } + + public void testNegate() { + ModifiableIntReference ref; + ref = this.buildIntReference(-3); + assertEquals(-3, ref.getValue()); + assertEquals(3, ref.negate()); + assertEquals(3, ref.getValue()); + + ref.setValue(3); + assertEquals(3, ref.getValue()); + assertEquals(-3, ref.negate()); + assertEquals(-3, ref.getValue()); + } + + public void testNegateExact() { + ModifiableIntReference ref; + ref = this.buildIntReference(-3); + assertEquals(-3, ref.getValue()); + assertEquals(3, ref.negateExact()); + assertEquals(3, ref.getValue()); + + ref.setValue(3); + assertEquals(3, ref.getValue()); + assertEquals(-3, ref.negateExact()); + assertEquals(-3, ref.getValue()); + } + + public void testSetZero() { + ModifiableIntReference ref; + ref = this.buildIntReference(-3); + assertEquals(-3, ref.getValue()); + assertEquals(-3, ref.setZero()); + assertEquals(0, ref.getValue()); + } + + public void testAddInt() { + ModifiableIntReference ref; + int value; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + value = ref.add(3); + assertEquals(3, value); + assertEquals(3, ref.getValue()); + + value = ref.add(-7); + assertEquals(-4, value); + assertEquals(-4, ref.getValue()); + } + + public void testAddExactInt() { + ModifiableIntReference ref; + int value; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + value = ref.addExact(3); + assertEquals(3, value); + assertEquals(3, ref.getValue()); + + value = ref.addExact(-7); + assertEquals(-4, value); + assertEquals(-4, ref.getValue()); + } + + public void testIncrement() { + ModifiableIntReference ref; + int value; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + value = ref.increment(); + assertEquals(1, value); + assertEquals(1, ref.getValue()); + } + + public void testIncrementExact() { + ModifiableIntReference ref; + int value; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + value = ref.incrementExact(); + assertEquals(1, value); + assertEquals(1, ref.getValue()); + } + + public void testSubtractInt() { + ModifiableIntReference ref; + int count; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + count = ref.subtract(3); + assertEquals(-3, count); + assertEquals(-3, ref.getValue()); + + count = ref.subtract(-7); + assertEquals(4, count); + assertEquals(4, ref.getValue()); + } + + public void testSubtractExactInt() { + ModifiableIntReference ref; + int count; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + count = ref.subtractExact(3); + assertEquals(-3, count); + assertEquals(-3, ref.getValue()); + + count = ref.subtractExact(-7); + assertEquals(4, count); + assertEquals(4, ref.getValue()); + } + + public void testDecrement() { + ModifiableIntReference ref; + int count; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + count = ref.decrement(); + assertEquals(-1, count); + assertEquals(-1, ref.getValue()); + } + + public void testDecrementExact() { + ModifiableIntReference ref; + int count; + ref = this.buildIntReference(); + assertEquals(0, ref.getValue()); + + count = ref.decrementExact(); + assertEquals(-1, count); + assertEquals(-1, ref.getValue()); + } + + public void testHalve() { + ModifiableIntReference ref; + ref = this.buildIntReference(44); + assertEquals(44, ref.getValue()); + assertEquals(22, ref.halve()); + assertEquals(22, ref.getValue()); + } + + public void testTwice() { + ModifiableIntReference ref; + ref = this.buildIntReference(44); + assertEquals(44, ref.getValue()); + assertEquals(88, ref.twice()); + assertEquals(88, ref.getValue()); + } + + public void testTwiceExact() { + ModifiableIntReference ref; + ref = this.buildIntReference(44); + assertEquals(44, ref.getValue()); + assertEquals(88, ref.twiceExact()); + assertEquals(88, ref.getValue()); + } + + public void testMultiplyInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(3); + assertEquals(3, ref.getValue()); + assertEquals(9, ref.multiply(3)); + assertEquals(9, ref.getValue()); + } + + public void testMultiplyExactInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(3); + assertEquals(3, ref.getValue()); + assertEquals(9, ref.multiplyExact(3)); + assertEquals(9, ref.getValue()); + } + + public void testDivideInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(24); + assertEquals(24, ref.getValue()); + assertEquals(8, ref.divide(3)); + assertEquals(8, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(1, ref.divide(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(-1, ref.divide(3)); + assertEquals(-1, ref.getValue()); + } + + public void testFloorDivideInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(24); + assertEquals(24, ref.getValue()); + assertEquals(8, ref.floorDivide(3)); + assertEquals(8, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(1, ref.floorDivide(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(-2, ref.floorDivide(3)); + assertEquals(-2, ref.getValue()); + } + + public void testRemainderInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(25); + assertEquals(25, ref.getValue()); + assertEquals(1, ref.remainder(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(1, ref.remainder(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(1, ref.remainder(-3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(-1, ref.remainder(3)); + assertEquals(-1, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(-1, ref.remainder(-3)); + assertEquals(-1, ref.getValue()); + } + + public void testFloorRemainderInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(25); + assertEquals(25, ref.getValue()); + assertEquals(1, ref.floorRemainder(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(1, ref.floorRemainder(3)); + assertEquals(1, ref.getValue()); + + ref = this.buildIntReference(4); + assertEquals(4, ref.getValue()); + assertEquals(-2, ref.floorRemainder(-3)); + assertEquals(-2, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(2, ref.floorRemainder(3)); + assertEquals(2, ref.getValue()); + + ref = this.buildIntReference(-4); + assertEquals(-4, ref.getValue()); + assertEquals(-1, ref.floorRemainder(-3)); + assertEquals(-1, ref.getValue()); + } + + public void testMinInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(25); + assertEquals(25, ref.getValue()); + assertEquals(3, ref.min(3)); + assertEquals(3, ref.getValue()); + assertEquals(3, ref.min(33)); + assertEquals(3, ref.getValue()); + } + + public void testMaxInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(25); + assertEquals(25, ref.getValue()); + assertEquals(25, ref.max(3)); + assertEquals(25, ref.getValue()); + assertEquals(30, ref.max(30)); + assertEquals(30, ref.getValue()); + assertEquals(30, ref.max(3)); + assertEquals(30, ref.getValue()); + } + + public void testCommitIntInt() { + ModifiableIntReference ref; + ref = this.buildIntReference(25); + assertTrue(ref.commit(-3, 25)); + assertEquals(-3, ref.getValue()); + assertFalse(ref.commit(22, 25)); + assertEquals(-3, ref.getValue()); + } + + public void testSwapRef() throws Exception { + ModifiableIntReference ref1 = this.buildIntReference(33); + ModifiableIntReference ref2 = ref1; + assertEquals(33, ref1.swap(ref2)); + + ref2 = this.buildIntReference(-7); + assertEquals(-7, ref1.swap(ref2)); + assertEquals(-7, ref1.getValue()); + assertEquals(33, ref2.getValue()); + + ref1.setValue(42); + ref2.setValue(42); + assertEquals(42, ref1.swap(ref2)); + assertEquals(42, ref1.getValue()); + assertEquals(42, ref2.getValue()); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ReferenceToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ReferenceToolsTests.java new file mode 100644 index 0000000000..5215689fa4 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/ReferenceToolsTests.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import java.lang.reflect.InvocationTargetException; +import org.eclipse.jpt.common.utility.internal.ClassTools; +import org.eclipse.jpt.common.utility.internal.reference.ReferenceTools; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public class ReferenceToolsTests + extends TestCase +{ + public ReferenceToolsTests(String name) { + super(name); + } + + public void testBooleanReference() { + assertTrue(ReferenceTools.booleanReference(true).getValue()); + assertFalse(ReferenceTools.booleanReference(false).getValue()); + } + + public void testConstructor() { + boolean exCaught = false; + try { + Object at = ClassTools.newInstance(ReferenceTools.class); + fail("bogus: " + at); + } catch (RuntimeException ex) { + if (ex.getCause() instanceof InvocationTargetException) { + if (ex.getCause().getCause() instanceof UnsupportedOperationException) { + exCaught = true; + } + } + } + assertTrue(exCaught); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleBooleanReferenceTests.java index ba9b630d4e..89037223d0 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleBooleanReferenceTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleBooleanReferenceTests.java @@ -9,20 +9,19 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.reference; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.reference.SimpleBooleanReference; +import org.eclipse.jpt.common.utility.reference.ModifiableBooleanReference; -@SuppressWarnings("nls") public class SimpleBooleanReferenceTests - extends TestCase + extends ModifiableBooleanReferenceTests { public SimpleBooleanReferenceTests(String name) { super(name); } - public void testGetValue() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.getValue()); + @Override + protected ModifiableBooleanReference buildBooleanReference(boolean value) { + return new SimpleBooleanReference(value); } public void testGetValueDefault() { @@ -30,194 +29,9 @@ public class SimpleBooleanReferenceTests assertFalse(br.getValue()); } - public void testIs() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.is(true)); - assertFalse(br.is(false)); - } - - public void testIsNot() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertFalse(br.isNot(true)); - assertTrue(br.isNot(false)); - } - - public void testIsTrue() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.isTrue()); - } - - public void testIsFalse() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertFalse(br.isFalse()); - br.setFalse(); - assertTrue(br.isFalse()); - } - - public void testSetValue() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.getValue()); - br.setValue(false); - assertFalse(br.getValue()); - } - - public void testFlip() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.getValue()); - assertFalse(br.flip()); - assertFalse(br.getValue()); - assertTrue(br.flip()); - assertTrue(br.getValue()); - } - - public void testAnd() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.and(true)); - assertTrue(br.getValue()); - - assertFalse(br.and(false)); - assertFalse(br.getValue()); - - assertFalse(br.and(true)); - assertFalse(br.getValue()); - - assertFalse(br.and(false)); - assertFalse(br.getValue()); - } - - public void testOr() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.or(true)); - assertTrue(br.getValue()); - - assertTrue(br.or(false)); - assertTrue(br.getValue()); - - assertTrue(br.setValue(false)); - assertFalse(br.or(false)); - assertFalse(br.getValue()); - - assertTrue(br.or(true)); - assertTrue(br.getValue()); - } - - public void testXor() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertFalse(br.xor(true)); - assertFalse(br.getValue()); - - assertFalse(br.setValue(true)); - assertTrue(br.xor(false)); - assertTrue(br.getValue()); - - assertTrue(br.setValue(false)); - assertFalse(br.xor(false)); - assertFalse(br.getValue()); - - assertFalse(br.setValue(false)); - assertTrue(br.xor(true)); - assertTrue(br.getValue()); - } - - public void testSetNotBoolean() { - SimpleBooleanReference br = new SimpleBooleanReference(false); - assertFalse(br.getValue()); - br.setNot(true); - assertFalse(br.getValue()); - br.setNot(true); - assertFalse(br.getValue()); - br.setNot(false); - assertTrue(br.getValue()); - } - - public void testSetTrue() { - SimpleBooleanReference br = new SimpleBooleanReference(false); - assertFalse(br.getValue()); - br.setTrue(); - assertTrue(br.getValue()); - } - - public void testSetFalse() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.getValue()); - br.setFalse(); - assertFalse(br.getValue()); - } - - public void testCommit() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.commit(false, true)); - assertFalse(br.getValue()); - - assertFalse(br.commit(false, true)); - assertFalse(br.getValue()); - - assertTrue(br.commit(true, false)); - assertTrue(br.getValue()); - - assertFalse(br.commit(true, false)); - assertTrue(br.getValue()); - - assertFalse(br.commit(false, false)); - assertTrue(br.getValue()); - - assertTrue(br.setValue(false)); - assertFalse(br.commit(true, true)); - assertFalse(br.getValue()); - } - - public void testSwap_sameObject() { - SimpleBooleanReference br = new SimpleBooleanReference(true); - assertTrue(br.swap(br)); - assertTrue(br.getValue()); - } - - public void testSwap_sameValues() { - SimpleBooleanReference br1 = new SimpleBooleanReference(true); - SimpleBooleanReference br2 = new SimpleBooleanReference(true); - assertTrue(br1.swap(br2)); - assertTrue(br1.getValue()); - assertTrue(br2.getValue()); - } - - public void testSwap_differentValues1() { - SimpleBooleanReference br1 = new SimpleBooleanReference(true); - SimpleBooleanReference br2 = new SimpleBooleanReference(false); - assertFalse(br1.swap(br2)); - assertFalse(br1.getValue()); - assertTrue(br2.getValue()); - } - - public void testSwap_differentValues2() { - SimpleBooleanReference br1 = new SimpleBooleanReference(false); - SimpleBooleanReference br2 = new SimpleBooleanReference(true); - assertTrue(br1.swap(br2)); - assertTrue(br1.getValue()); - assertFalse(br2.getValue()); - } - - public void testEquals() { - SimpleBooleanReference br1 = new SimpleBooleanReference(false); - SimpleBooleanReference br2 = new SimpleBooleanReference(true); - assertTrue(br1.equals(br1)); - assertFalse(br1.equals(br2)); - } - - public void testHashCode() { - SimpleBooleanReference br1 = new SimpleBooleanReference(false); - assertEquals(br1.hashCode(), br1.hashCode()); - } - public void testClone() { SimpleBooleanReference br = new SimpleBooleanReference(true); SimpleBooleanReference clone = br.clone(); assertTrue(clone.getValue()); } - - public void testToString() { - SimpleBooleanReference br1 = new SimpleBooleanReference(true); - assertEquals("[true]", br1.toString()); - br1.setFalse(); - assertEquals("[false]", br1.toString()); - } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleIntReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleIntReferenceTests.java index f85d7cd6c3..3d4d1bb277 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleIntReferenceTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/SimpleIntReferenceTests.java @@ -9,18 +9,22 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.reference; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.reference.SimpleIntReference; +import org.eclipse.jpt.common.utility.reference.ModifiableIntReference; import org.eclipse.jpt.common.utility.tests.internal.TestTools; -@SuppressWarnings("nls") public class SimpleIntReferenceTests - extends TestCase + extends ModifiableIntReferenceTests { public SimpleIntReferenceTests(String name) { super(name); } + @Override + protected ModifiableIntReference buildIntReference(int value) { + return new SimpleIntReference(value); + } + public void testCtors() { SimpleIntReference ir; ir = new SimpleIntReference(); @@ -31,262 +35,6 @@ public class SimpleIntReferenceTests assertEquals(-7, ir.getValue()); } - public void testEqualsInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertTrue(ir.equals(0)); - assertFalse(ir.equals(7)); - - ir = new SimpleIntReference(7); - assertTrue(ir.equals(7)); - assertFalse(ir.equals(0)); - } - - public void testNotEqualInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertFalse(ir.notEqual(0)); - assertTrue(ir.notEqual(7)); - - ir = new SimpleIntReference(7); - assertFalse(ir.notEqual(7)); - assertTrue(ir.notEqual(0)); - } - - public void testIsZero() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertTrue(ir.isZero()); - - ir = new SimpleIntReference(7); - assertFalse(ir.isZero()); - } - - public void testIsNotZero() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertFalse(ir.isNotZero()); - - ir = new SimpleIntReference(7); - assertTrue(ir.isNotZero()); - } - - public void testIsGreaterThanInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertTrue(ir.isGreaterThan(-1)); - assertFalse(ir.isGreaterThan(0)); - assertFalse(ir.isGreaterThan(7)); - } - - public void testIsGreaterThanOrEqualInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertTrue(ir.isGreaterThanOrEqual(-1)); - assertTrue(ir.isGreaterThanOrEqual(0)); - assertFalse(ir.isGreaterThanOrEqual(7)); - } - - public void testIsLessThanInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertFalse(ir.isLessThan(-1)); - assertFalse(ir.isLessThan(0)); - assertTrue(ir.isLessThan(7)); - } - - public void testIsLessThanOrEqualInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(); - assertFalse(ir.isLessThanOrEqual(-1)); - assertTrue(ir.isLessThanOrEqual(0)); - assertTrue(ir.isLessThanOrEqual(7)); - } - - public void testIsPositive() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertFalse(ir.isPositive()); - - ir = new SimpleIntReference(); - assertFalse(ir.isPositive()); - - ir = new SimpleIntReference(7); - assertTrue(ir.isPositive()); - } - - public void testIsNotPositive() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertTrue(ir.isNotPositive()); - - ir = new SimpleIntReference(); - assertTrue(ir.isNotPositive()); - - ir = new SimpleIntReference(7); - assertFalse(ir.isNotPositive()); - } - - public void testIsNegative() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertTrue(ir.isNegative()); - - ir = new SimpleIntReference(); - assertFalse(ir.isNegative()); - - ir = new SimpleIntReference(7); - assertFalse(ir.isNegative()); - } - - public void testIsNotNegative() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertFalse(ir.isNotNegative()); - - ir = new SimpleIntReference(); - assertTrue(ir.isNotNegative()); - - ir = new SimpleIntReference(7); - assertTrue(ir.isNotNegative()); - } - - public void testSetValueInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertEquals(-3, ir.getValue()); - assertEquals(-3, ir.setValue(4)); - assertEquals(4, ir.getValue()); - } - - public void testAbs() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertEquals(-3, ir.getValue()); - assertEquals(3, ir.abs()); - - ir.setValue(3); - assertEquals(3, ir.getValue()); - assertEquals(3, ir.abs()); - } - - public void testNeg() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertEquals(-3, ir.getValue()); - assertEquals(3, ir.negate()); - - ir.setValue(3); - assertEquals(3, ir.getValue()); - assertEquals(-3, ir.negate()); - } - - public void testSetZero() { - SimpleIntReference ir; - ir = new SimpleIntReference(-3); - assertEquals(-3, ir.getValue()); - assertEquals(-3, ir.setZero()); - assertEquals(0, ir.getValue()); - } - - public void testAddInt() { - SimpleIntReference ir; - int value; - ir = new SimpleIntReference(); - assertEquals(0, ir.getValue()); - - value = ir.add(3); - assertEquals(3, value); - - ir.setValue(3); - value = ir.add(-7); - assertEquals(-4, value); - } - - public void testIncrement() { - SimpleIntReference ir; - int value; - ir = new SimpleIntReference(); - assertEquals(0, ir.getValue()); - - value = ir.increment(); - assertEquals(1, value); - assertEquals(1, ir.getValue()); - } - - public void testSubtractInt() { - SimpleIntReference ir; - int count; - ir = new SimpleIntReference(); - assertEquals(0, ir.getValue()); - - count = ir.subtract(3); - assertEquals(-3, count); - - ir.setValue(-3); - count = ir.subtract(-7); - assertEquals(4, count); - } - - public void testDecrement() { - SimpleIntReference ir; - int count; - ir = new SimpleIntReference(); - assertEquals(0, ir.getValue()); - - count = ir.decrement(); - assertEquals(-1, count); - assertEquals(-1, ir.getValue()); - } - - public void testMultiplyInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(3); - assertEquals(3, ir.getValue()); - assertEquals(9, ir.multiply(3)); - } - - public void testDivideInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(24); - assertEquals(24, ir.getValue()); - assertEquals(8, ir.divide(3)); - } - - public void testRemainderInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(25); - assertEquals(25, ir.getValue()); - assertEquals(1, ir.remainder(3)); - } - - public void testMinInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(25); - assertEquals(25, ir.getValue()); - assertEquals(3, ir.min(3)); - assertEquals(3, ir.getValue()); - assertEquals(3, ir.min(33)); - } - - public void testMaxInt() { - SimpleIntReference ir; - ir = new SimpleIntReference(25); - assertEquals(25, ir.getValue()); - assertEquals(25, ir.max(3)); - assertEquals(30, ir.max(30)); - } - - public void testCompareToIntReference() { - SimpleIntReference ir1 = new SimpleIntReference(44); - SimpleIntReference ir2 = new SimpleIntReference(44); - assertTrue(ir1.compareTo(ir2) == 0); - ir2 = new SimpleIntReference(55); - assertTrue(ir1.compareTo(ir2) < 0); - ir2 = new SimpleIntReference(33); - assertTrue(ir1.compareTo(ir2) > 0); - } - public void testClone() { SimpleIntReference ir1 = new SimpleIntReference(44); SimpleIntReference ir2 = ir1.clone(); @@ -300,10 +48,4 @@ public class SimpleIntReferenceTests assertEquals(44, ir2.getValue()); assertNotSame(ir1, ir2); } - - public void testToString() { - SimpleIntReference ir; - ir = new SimpleIntReference(5); - assertEquals("[5]", ir.toString()); - } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/TrueBooleanReferenceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/TrueBooleanReferenceTests.java new file mode 100644 index 0000000000..fff5070fb2 --- /dev/null +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/reference/TrueBooleanReferenceTests.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2015 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.tests.internal.reference; + +import org.eclipse.jpt.common.utility.internal.reference.TrueBooleanReference; +import org.eclipse.jpt.common.utility.reference.BooleanReference; +import org.eclipse.jpt.common.utility.tests.internal.TestTools; +import junit.framework.TestCase; + +@SuppressWarnings("nls") +public class TrueBooleanReferenceTests + extends TestCase +{ + public TrueBooleanReferenceTests(String name) { + super(name); + } + + public void testGetValue() { + BooleanReference ref = TrueBooleanReference.instance(); + assertTrue(ref.getValue()); + } + + public void testIs() { + BooleanReference ref = TrueBooleanReference.instance(); + assertTrue(ref.is(true)); + assertFalse(ref.is(false)); + } + + public void testIsNot() { + BooleanReference ref = TrueBooleanReference.instance(); + assertFalse(ref.isNot(true)); + assertTrue(ref.isNot(false)); + } + + public void testIsTrue() { + BooleanReference ref = TrueBooleanReference.instance(); + assertTrue(ref.isTrue()); + } + + public void testIsFalse() { + BooleanReference ref = TrueBooleanReference.instance(); + assertFalse(ref.isFalse()); + } + + public void testToString() { + BooleanReference ref = TrueBooleanReference.instance(); + assertEquals("[true]", ref.toString()); + } + + public void testSerialization() throws Exception { + BooleanReference ref = TrueBooleanReference.instance(); + assertSame(ref, TestTools.serialize(ref)); + } +} |