|
From: <fra...@ya...> - 2002-03-28 16:30:18
|
Hello again !
Here's my submission for the Null class.
Index: Null.java
===================================================================
RCS file:
/cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/Null.java,v
retrieving revision 1.2
diff -u -r1.2 Null.java
--- Null.java 22 Feb 2002 10:28:44 -0000 1.2
+++ Null.java 28 Mar 2002 16:26:39 -0000
@@ -1,25 +1,159 @@
package com.mockobjects.util;
+/**
+ * A class that represents the <code>null</code> value.
+ * The {@link com.mockobjects.util.Null Null} class is used when an
+ * {@link com.mockobjects.Expectation Expectation} is set to expect nothing.
+ * <p>
+ * <b>Example usage:</b>
+ * <pre>
+ * public class MockX {
+ * private Expectation... anExpectation = new Expectation...(...);
+ *
+ * public MockX() {
+ * anExpectation.setExpectNothing();
+ * }
+ *
+ * public void setAnExpectation(Object value) {
+ * anExpectation.setExpected(value);
+ * }
+ *
+ * public void setActual(Object value) {
+ * anExpectation.setActual(value);
+ * }
+ * }
+ * </pre>
+ * The act of calling {@link com.mockobjects.Expectation#setExpectNothing()
Expectation.setExpectNothing()}
+ * tells the expectation that it should expect no values to change. Since
+ * all {@link com.mockobjects.util.Null Null} objects are equal to themselves,
+ * most expectations set their expected value to an instance of
+ * {@link com.mockobjects.util.Null Null}, and at the same time, set their
actual
+ * value to another instance of {@link com.mockobjects.util.Null Null}.
+ * This way, when {@link com.mockobjects.Verifiable#verify() verify()} checks
+ * expectations, they will compare two {@link com.mockobjects.util.Null Null}
+ * objects together, which is guaranteed to succeed.
+ * <pre>
+ * ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must not be
+ * used to endorse or promote products derived from this software
+ * without prior written permission. For written permission, please
+ * contact ap...@ap....
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ * </pre>
+ * @author <a href="mailto:fb...@us...">Francois Beausoleil
(fb...@us...)</a>
+ * @version $Id$
+ */
public class Null {
+ /**
+ * The default description for all {@link com.mockobjects.util.Null Null}
+ * objects.
+ * This String is equal to "<code>Null</code>".
+ */
+ public static final String DEFAULT_DESCRIPTION = "Null";
+
+ /**
+ * A default {@link com.mockobjects.util.Null Null} object.
+ * Instead of always instantiating new {@link com.mockobjects.util.Null
Null}
+ * objects, consider using a reference to this object instead. This way,
+ * the virtual machine will not be taking the time required to instantiate
+ * an object everytime it is required.
+ */
+ public static final Null NULL = new Null();
+
+ /**
+ * The description of this {@link com.mockobjects.util.Null Null} object.
+ */
final private String myDescription;
+ /**
+ * Instantiates a new {@link com.mockobjects.util.Null Null} object with
+ * the default description.
+ * @see com.mockobjects.util.Null#DEFAULT_DESCRIPTION
+ */
public Null() {
- this("Null");
+ this(DEFAULT_DESCRIPTION);
}
+ /**
+ * Instantiates a new {@link com.mockobjects.util.Null Null} object and
+ * sets it's description.
+ * @param description
+ */
public Null(String description) {
super();
myDescription = description;
}
+ /**
+ * Determines equality between two objects.
+ * {@link com.mockobjects.util.Null Null} objects are only equal to
+ * another instance of themselves.
+ * @param other
+ */
public boolean equals(Object other) {
return other instanceof Null;
}
+ /**
+ * Returns this {@link com.mockobjects.util.Null Null} object's hashCode.
+ * All {@link com.mockobjects.util.Null Null} return the same
+ * hashCode value.
+ */
public int hashCode() {
- return "Null".hashCode();
+ return 0;
}
+ /**
+ * Returns a string representation of this {@link
com.mockobjects.util.Null Null}
+ * object.
+ * This merely returns the string passed to the constructor initially.
+ */
public String toString() {
return myDescription;
}
__________________________________________________________
Lèche-vitrine ou lèche-écran ?
magasinage.yahoo.ca
|
|
From: Jeff M. <je...@mk...> - 2002-03-28 18:22:41
|
I've stripped the license stuff out of this as I think it detracts from
the javadoc. Although at some point we need to insert a corrected
license into the source which won't be shown on every javadoc page.
On Thu, 2002-03-28 at 16:30, Francois Beausoleil wrote:
> Hello again !
>=20
> Here's my submission for the Null class.
>=20
> Index: Null.java
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> RCS file:
> /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/Null.=
java,v
> retrieving revision 1.2
> diff -u -r1.2 Null.java
> --- Null.java 22 Feb 2002 10:28:44 -0000 1.2
> +++ Null.java 28 Mar 2002 16:26:39 -0000
> @@ -1,25 +1,159 @@
> package com.mockobjects.util;
> =20
> +/**
> + * A class that represents the <code>null</code> value.
> + * The {@link com.mockobjects.util.Null Null} class is used when an
> + * {@link com.mockobjects.Expectation Expectation} is set to expect noth=
ing.
> + * <p>
> + * <b>Example usage:</b>
> + * <pre>
> + * public class MockX {
> + * private Expectation... anExpectation =3D new Expectation...(...);
> + *
> + * public MockX() {
> + * anExpectation.setExpectNothing();
> + * }
> + *
> + * public void setAnExpectation(Object value) {
> + * anExpectation.setExpected(value);
> + * }
> + *
> + * public void setActual(Object value) {
> + * anExpectation.setActual(value);
> + * }
> + * }
> + * </pre>
> + * The act of calling {@link com.mockobjects.Expectation#setExpectNothin=
g()
> Expectation.setExpectNothing()}
> + * tells the expectation that it should expect no values to change. Sin=
ce
> + * all {@link com.mockobjects.util.Null Null} objects are equal to thems=
elves,
> + * most expectations set their expected value to an instance of
> + * {@link com.mockobjects.util.Null Null}, and at the same time, set the=
ir
> actual
> + * value to another instance of {@link com.mockobjects.util.Null Null}.
> + * This way, when {@link com.mockobjects.Verifiable#verify() verify()} c=
hecks
> + * expectations, they will compare two {@link com.mockobjects.util.Null =
Null}
> + * objects together, which is guaranteed to succeed.
> + * <pre>
> + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> + * The Apache Software License, Version 1.1
> + *
> + * Copyright (c) 2001 The Apache Software Foundation. All rights
> + * reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + *
> + * 2. Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in
> + * the documentation and/or other materials provided with the
> + * distribution.
> + *
> + * 3. The end-user documentation included with the redistribution,
> + * if any, must include the following acknowledgment:
> + * "This product includes software developed by the
> + * Apache Software Foundation (http://www.apache.org/)."
> + * Alternately, this acknowledgment may appear in the software itself=
,
> + * if and wherever such third-party acknowledgments normally appear.
> + *
> + * 4. The names "Apache" and "Apache Software Foundation" must not be
> + * used to endorse or promote products derived from this software
> + * without prior written permission. For written permission, please
> + * contact ap...@ap....
> + *
> + * 5. Products derived from this software may not be called "Apache",
> + * nor may "Apache" appear in their name, without prior written
> + * permission of the Apache Software Foundation.
> + *
> + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> + *
> + * This software consists of voluntary contributions made by many
> + * individuals on behalf of the Apache Software Foundation. For more
> + * information on the Apache Software Foundation, please see
> + * <http://www.apache.org/>.
> + * </pre>
> + * @author <a href=3D"mailto:fb...@us...">Francois Beauso=
leil
> (fb...@us...)</a>
> + * @version $Id$
> + */
> public class Null {
> + /**
> + * The default description for all {@link com.mockobjects.util.Null =
Null}
> + * objects.
> + * This String is equal to "<code>Null</code>".
> + */
> + public static final String DEFAULT_DESCRIPTION =3D "Null";
> +
> + /**
> + * A default {@link com.mockobjects.util.Null Null} object.
> + * Instead of always instantiating new {@link com.mockobjects.util.N=
ull
> Null}
> + * objects, consider using a reference to this object instead. This =
way,
> + * the virtual machine will not be taking the time required to insta=
ntiate
> + * an object everytime it is required.
> + */
> + public static final Null NULL =3D new Null();
> +
> + /**
> + * The description of this {@link com.mockobjects.util.Null Null} ob=
ject.
> + */
> final private String myDescription;
> =20
> + /**
> + * Instantiates a new {@link com.mockobjects.util.Null Null} object =
with
> + * the default description.
> + * @see com.mockobjects.util.Null#DEFAULT_DESCRIPTION
> + */
> public Null() {
> - this("Null");
> + this(DEFAULT_DESCRIPTION);
> }
> =20
> + /**
> + * Instantiates a new {@link com.mockobjects.util.Null Null} object =
and
> + * sets it's description.
> + * @param description
> + */
> public Null(String description) {
> super();
> myDescription =3D description;
> }
> =20
> + /**
> + * Determines equality between two objects.
> + * {@link com.mockobjects.util.Null Null} objects are only equal to
> + * another instance of themselves.
> + * @param other
> + */
> public boolean equals(Object other) {
> return other instanceof Null;
> }
> =20
> + /**
> + * Returns this {@link com.mockobjects.util.Null Null} object's hash=
Code.
> + * All {@link com.mockobjects.util.Null Null} return the same
> + * hashCode value.
> + */
> public int hashCode() {
> - return "Null".hashCode();
> + return 0;
> }
> =20
> + /**
> + * Returns a string representation of this {@link
> com.mockobjects.util.Null Null}
> + * object.
> + * This merely returns the string passed to the constructor initiall=
y.
> + */
> public String toString() {
> return myDescription;
> }
>=20
>=20
> __________________________________________________________
> L=E8che-vitrine ou l=E8che-=E9cran ?
> magasinage.yahoo.ca
>=20
> _______________________________________________
> Mockobjects-java-dev mailing list
> Moc...@li...
> https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev
--=20
|