<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=3xT</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=3xT"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/3xT"/>
	<updated>2026-05-24T22:07:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25956</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25956"/>
		<updated>2009-10-14T04:42:29Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Deserialization with readResolve */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization with writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, if an instance of MyClass was to be serialized Java would look to first see if there was a method implemented called writeReplace as shown in the example.  If this method does exist, the return value of this method would be serialized instead.  In this example, a new instance of SerializationProxy would first be created and constructed with the integer parameter from MyClass and that object would be serialized.&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, if an object is deserialized, Java looks for a method called readResolve.  If readResolve exists, the return value of readResolve is returned instead of this object.  In this example, the SerializationProxy would first be deserialized and then Java will look for and find readResolve.  A new instance of MyClass would then be created with the integer parameter from the SerializationProxy and the instance of MyClass would be returned as the result of the deserialization.&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25953</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25953"/>
		<updated>2009-10-14T04:39:12Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Serialization with writeReplace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization with writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, if an instance of MyClass was to be serialized Java would look to first see if there was a method implemented called writeReplace as shown in the example.  If this method does exist, the return value of this method would be serialized instead.  In this example, a new instance of SerializationProxy would first be created and constructed with the integer parameter from MyClass and that object would be serialized.&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25951</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25951"/>
		<updated>2009-10-14T04:37:31Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Serialization with writeReplace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization with writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, if an instance of MyClass was to be serialized Java would look to first see if there was a method implemented called writeReplace as shown in the example.  If so as we do here, the return value of this method would be serialized instead.  In this example, a new instance of SerializationProxy would first be created and constructed with the integer parameter from MyClass and that object would be serialized.&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25950</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25950"/>
		<updated>2009-10-14T04:36:37Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Serialization with writeReplace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization with writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, if an instance of MyClass was to be serialized Java would look to first see if there was a method implemented called writeReplace as shown in the example.  If so as we do here, the return value of this method would be serialized instead.  A new instance of SerializationProxy would first be created and constructed with the integer parameter from MyClass and that object would be serialized.&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25948</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25948"/>
		<updated>2009-10-14T04:21:16Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Serialization writeReplace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization with writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25947</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25947"/>
		<updated>2009-10-14T04:21:05Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Implementation Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
=== Serialization writeReplace ===&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Deserialization with readResolve ===&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25626</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 18 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_18_i7&amp;diff=25626"/>
		<updated>2009-10-11T19:38:19Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Problem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Serialization Proxy Pattern =&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
When designing a class, it is preferred to have them be [http://en.wikipedia.org/wiki/Immutable_object immutable] because of guaranteed thread safety and consistent object state.  An immutable class is one where the state cannot be modified after it is instantiated.&lt;br /&gt;
&lt;br /&gt;
A problem arises in Java when needing a class to be [http://en.wikipedia.org/wiki/Serialization serializable].  In order to have a class be serializable the [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Serializable] interface must be implemented.  A class that is serializable is one that can be represented on disk as a sequence of bits. The reason this is a problem is not on serialization, but rather on deserialization.  During deserialization of a class, Java requires that the first non-serializable superclass have a no-argument constructor.  Java uses this constructor to instantiate the object and populate the fields.  This may be the case if the superclass is one that is immutable.  The answer here in most cases would be to make the class and superclass mutable and provide a no argument constructor in the superclass.  Serialization proxy pattern aims to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
The idea behind the serialization proxy pattern is simple.  On serialization, instead of having to remove the immutability that exists in the superclass and the class that needs to be serialized, a proxy class is serialized instead of the target class.  A proxy class in this context would be a class where enough information is stored in it to reconstruct the target class.  On deserialization, instead of returning an instance of the proxy class, the target class is instantiated with the information provided by the proxy class and returned in place of it.  The following diagram shows the design of what happens on serialization and deserialization.&lt;br /&gt;
&lt;br /&gt;
[[Image:i718design.png]]&lt;br /&gt;
&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
During serialization there is a method that Java looks for which is called writeReplace.  If writeReplace exists, the value returned from this method will be serialized in place of the current class.  This is where we would return a proxy object which stores enough information to reconstruct what we actually want to serialize.  An example of an implementation of writeReplace can be identified in the following code snippet.  In brief, there is a simple class called MyClass which holds a single integer value and there is an inner class SerializationProxy.  The SerializationProxy class used as the serialization proxy object in the writeReplace method when serializing instances of MyClass.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    private final int value;&lt;br /&gt;
    &lt;br /&gt;
    public MyClass(int value) {&lt;br /&gt;
        this.value = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getValue() {&lt;br /&gt;
        return this.value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private Object writeReplace() {&lt;br /&gt;
        return new SerializationProxy(this);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static final class SerializationProxy implements Serializable {&lt;br /&gt;
        private final int value;&lt;br /&gt;
&lt;br /&gt;
        public SerializationProxy(MyClass myClass) {&lt;br /&gt;
            this.value = myClass.getValue();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
During deserialization there is a method that Java looks for which is called readResolve.  If readResolve exists, the value returned from this method will instead be the result of the deserialization of this object.  This method would be implemented in the proxy class and the constructor for the class we want to reconstruct would be invoked and returned as the value returned by readResolve.  An example implementation of readResolve would be the following which would be added inside of the SerializationProxy class from the previous example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private Object readResolve() {&lt;br /&gt;
    return new MyClass(this.value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idiomatic Usage ==&lt;br /&gt;
The idiom for implementing serialization proxy pattern is using an inner class that is declared as private, static, and final.  The reason the class is declared private is because it should not be visible to anyone other then the enclosing class, static is because it should not share any instance variables with the parent, and final because this class should never be extended.  Additionally since the class is hidden because it is an inner class, the serialization proxy used will be transparent to all users of this class regarding serialization.  This is a good thing because we don't want users of this class to have to deal with the serialization proxy.  An example of this structure is the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class MyClass implements Serializable {&lt;br /&gt;
    ...&lt;br /&gt;
    private static final SerializationProxy implements Serializable {&lt;br /&gt;
        ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Using the serialization proxy pattern brings a two important benefits to the table when dealing with serialization of immutable classes.  First, serialization is made possible for classes where a no argument constructor in the superclass would be needed without losing immutability of classes that may already be in place.  Second, the usage of serialization proxy pattern is completely transparent to the clients of the class, they do not ever need to know that there is a serialization proxy.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html Java API - Serializable]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.jguru.com/faq/view.jsp?EID=251942 jGuru - Are classes that implement Serializable required to have no-argument constructors?]&lt;br /&gt;
&lt;br /&gt;
3. [http://java.sun.com/docs/books/effective/ Effective Java]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Immutable_object Wikipedia - Immutable object]&lt;br /&gt;
&lt;br /&gt;
5. [http://en.wikipedia.org/wiki/Serialization Wikipedia - Serialization]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18641</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18641"/>
		<updated>2009-09-08T05:08:12Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18640</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18640"/>
		<updated>2009-09-08T05:07:19Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Diagram of showing where mock objects fit in:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18639</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18639"/>
		<updated>2009-09-08T05:07:09Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Diagram of showing mock objects fit in:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18638</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18638"/>
		<updated>2009-09-08T05:06:48Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18637</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18637"/>
		<updated>2009-09-08T05:06:21Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18193</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18193"/>
		<updated>2009-09-07T19:47:19Z</updated>

		<summary type="html">&lt;p&gt;3xT: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18192</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18192"/>
		<updated>2009-09-07T19:47:06Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Criteria in choosing a Mock Object Framework */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18190</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18190"/>
		<updated>2009-09-07T19:45:11Z</updated>

		<summary type="html">&lt;p&gt;3xT: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in jMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Criteria in choosing a Mock Object Framework ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ jMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18188</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18188"/>
		<updated>2009-09-07T19:41:48Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Existing Mock Frameworks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Object Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18187</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18187"/>
		<updated>2009-09-07T19:40:22Z</updated>

		<summary type="html">&lt;p&gt;3xT: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18186</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18186"/>
		<updated>2009-09-07T19:40:05Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Existing Mock Frameworks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Frameworks ==&lt;br /&gt;
*Java&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18185</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18185"/>
		<updated>2009-09-07T19:39:54Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;br /&gt;
&lt;br /&gt;
== Existing Mock Frameworks ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18184</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18184"/>
		<updated>2009-09-07T19:39:22Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
2. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
4. [http://en.wikipedia.org/wiki/Mock_object Wikipedia - Mock object]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18183</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18183"/>
		<updated>2009-09-07T19:38:43Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. [http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches Approaches to Mocking]&lt;br /&gt;
&lt;br /&gt;
3. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18182</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18182"/>
		<updated>2009-09-07T19:38:25Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Java Mock Frameworks Comparison]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18181</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18181"/>
		<updated>2009-09-07T19:37:52Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. [http://msdn.microsoft.com/en-us/magazine/dd882516.aspx Using Mocks And Tests To Design Role-Based Objects]&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18179</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18179"/>
		<updated>2009-09-07T19:37:21Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* What are Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where its responsibility is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18177</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18177"/>
		<updated>2009-09-07T19:33:51Z</updated>

		<summary type="html">&lt;p&gt;3xT: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18175</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18175"/>
		<updated>2009-09-07T19:33:22Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
This step involves ensuring that everything that was expected of the mock object was satisfied such as the number of method calls to a certain method.&lt;br /&gt;
&lt;br /&gt;
An example in JMock:&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
This example shows a context that is used while using the JMock framework which is initialized at the top.  At the end a method assertIsSatisfied() is called on the context.  In this case, JMock uses the context to create mock objects and it is aware of what expectations mock objects had.  The assertIsSatisfied() method will throw an exception depending on if the expectations of the mock objects were or were not satisfied.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18164</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18164"/>
		<updated>2009-09-07T19:28:22Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    &amp;lt;Create mock object&amp;gt;&lt;br /&gt;
    &amp;lt;Define the method stubs&amp;gt;&lt;br /&gt;
    &amp;lt;Define the expectations&amp;gt;&lt;br /&gt;
    &amp;lt;Execute the test code&amp;gt;&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18162</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18162"/>
		<updated>2009-09-07T19:28:04Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    Create mock object...&lt;br /&gt;
    Define the method stubs...&lt;br /&gt;
    Define the expectations...&lt;br /&gt;
    Execute the test code...&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18161</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18161"/>
		<updated>2009-09-07T19:27:45Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
    // Create mock object.&lt;br /&gt;
    // Define the method stubs.&lt;br /&gt;
    // Define the expectations.&lt;br /&gt;
    // Execute the test code.&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18160</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18160"/>
		<updated>2009-09-07T19:27:36Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
    Mockery context = new Mockery();&lt;br /&gt;
&lt;br /&gt;
    // Create mock object.&lt;br /&gt;
    // Define the method stubs.&lt;br /&gt;
    // Define the expectations.&lt;br /&gt;
    // Execute the test code.&lt;br /&gt;
&lt;br /&gt;
    context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18156</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18156"/>
		<updated>2009-09-07T19:26:46Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Verify the expectations were satisfied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
Mockery context = new Mockery();&lt;br /&gt;
&lt;br /&gt;
// Create mock object&lt;br /&gt;
// Define &lt;br /&gt;
&lt;br /&gt;
context.assertIsSatisfied();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18154</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18154"/>
		<updated>2009-09-07T19:22:40Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Execution of the test code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the mocked object.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    PositionProcessor processor = new PositionProcessor();&lt;br /&gt;
    processor.process(mockPositionProvider);&lt;br /&gt;
&lt;br /&gt;
In this example we have a PositionProcessor class which processes PositionProviders.  A case of code that is involved with interacting with the mocked object is when a PositionProvider is processed we might expect the getX() method to be called at least once.&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18151</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18151"/>
		<updated>2009-09-07T19:18:22Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the expectations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockPositionProvider.getX() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18150</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18150"/>
		<updated>2009-09-07T19:18:03Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the stubbed methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10. An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18149</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18149"/>
		<updated>2009-09-07T19:16:58Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the expectations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.getX()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18148</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18148"/>
		<updated>2009-09-07T19:16:32Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the stubbed methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockPositionProvider.should_receive(:getX).times(1).and_return(10);&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockPositionProvider object the getX method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockPositionProvider object should receive getX one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18147</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18147"/>
		<updated>2009-09-07T19:15:15Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Create the mock object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    PositionProvider mockPositionProvider = mock(PositionProvider.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called mockPositionProvider which is a mock object of the PositionProvider class.  This variable is initialized to have the value mock(PositionProvider.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the PositionProvider class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18145</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18145"/>
		<updated>2009-09-07T19:14:20Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Execution of the test code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.getInt();&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a method called getInt().  In this example we have an IntGetter class which is composed of a Role class.  The IntGetter has a method called getInt as well, when this method is called we expect the&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18142</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18142"/>
		<updated>2009-09-07T19:12:12Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Execution of the test code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
This step involves invoking the code that is involved with interacting with the role that is being mocked.&lt;br /&gt;
&lt;br /&gt;
An example not specific to any Mock Object Framework:&lt;br /&gt;
&lt;br /&gt;
    IntGetter intGetter = new IntGetter(mockRole);&lt;br /&gt;
    intGetter.get()&lt;br /&gt;
&lt;br /&gt;
In the above examples we assumed that the Role class had a&lt;br /&gt;
&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18140</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18140"/>
		<updated>2009-09-07T19:08:44Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the expectations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
This is plainly calling a method on a mocked object.  In EasyMock, this is how expectations are created.  Test code would be run at some point after this method call and then when the mock object is verified it will check if mockRole.getInt() was indeed called through the test code.&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18139</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18139"/>
		<updated>2009-09-07T19:07:06Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the expectations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.&lt;br /&gt;
&lt;br /&gt;
An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.getInt()&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18137</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18137"/>
		<updated>2009-09-07T19:05:18Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the stubbed methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.&lt;br /&gt;
&lt;br /&gt;
An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.  An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18136</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18136"/>
		<updated>2009-09-07T19:04:58Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Create the mock object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.  An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18135</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18135"/>
		<updated>2009-09-07T19:04:49Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Create the mock object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
'''An example in Mockito:'''&lt;br /&gt;
&lt;br /&gt;
    *Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.  An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18134</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18134"/>
		<updated>2009-09-07T19:04:35Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Create the mock object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  &lt;br /&gt;
&lt;br /&gt;
'''An example in Mockito:'''&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.  An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18133</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18133"/>
		<updated>2009-09-07T19:04:24Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the expectations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
This step involves defining what is expected to happen to the mock object when the test code is run such as what methods should be called, how many times should the methods be called, or what exceptions should be thrown.  An example in EasyMock:&lt;br /&gt;
&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18132</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18132"/>
		<updated>2009-09-07T19:01:06Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the stubbed methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(1).&lt;br /&gt;
        and_return(10)&lt;br /&gt;
&lt;br /&gt;
This uses chained method calls to declare that on the mockRole object the getInt method should be called, the method should be called one time, and when called the method should return 10.  An important feature to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability when designing their APIs.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt one time and return 10&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18130</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18130"/>
		<updated>2009-09-07T18:56:58Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Define the stubbed methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(3).&lt;br /&gt;
        and_return(10, 12, 14)&lt;br /&gt;
&lt;br /&gt;
''One of the first things to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt three times and return 10, 12, and 14&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18129</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18129"/>
		<updated>2009-09-07T18:55:31Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Why use Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example of a relationship between DataConsumers and DataProviders:'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(3).&lt;br /&gt;
        and_return(10, 12, 14)&lt;br /&gt;
&lt;br /&gt;
One of the first things to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt three times and return 10, 12, and 14&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18128</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 2 i7</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_2_i7&amp;diff=18128"/>
		<updated>2009-09-07T18:55:18Z</updated>

		<summary type="html">&lt;p&gt;3xT: /* Why use Mock Object Frameworks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What are Mock Object Frameworks? ==&lt;br /&gt;
&amp;quot;Mock object frameworks&amp;quot; allow for the creation and use of &amp;quot;mock objects&amp;quot; which are used to mock existing roles in a system.  Roles are identified in a system as an interface or abstract type where the responsibility of the object is made aware through its definition.  Mock objects are typically provided behavior and expectations programatically to allow for testing interactions with them.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where mock objects fit in:'''&lt;br /&gt;
[[Image:Whatismocking.png]]&lt;br /&gt;
&lt;br /&gt;
== Why use Mock Object Frameworks? ==&lt;br /&gt;
Using mock objects allows for testing interaction with an interface rather than an implementation.  There are a variety of reasons this may be beneficial, some of which may be when the mocked object is:&lt;br /&gt;
* non-deterministic (i.e. time of day)&lt;br /&gt;
* able to exhibit behavior that is difficult to reproduce directly (i.e.  time out exception)&lt;br /&gt;
* slow (i.e.  accessing a database)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example role in a system might be a DataProvider interface.  Two implementation independent features of the getData() method of this interface may be that it returns a Data object and is able to throw a DataRetrievalException.  An example definition is shown below in Java:&lt;br /&gt;
&lt;br /&gt;
    interface DataProvider {&lt;br /&gt;
        Data getData() throws DataRetrievalException;&lt;br /&gt;
        boolean hasNext();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A mock object in this case would be useful in a test which involves the interaction with a DataProvider, such as providing data to a DataConsumer class.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example of a relationship between DataConsumers and DataProviders:&lt;br /&gt;
&lt;br /&gt;
[[Image:Mockdataprovider.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The implementation of the DataProvider is irrelevant to testing the correctness of a DataConsumer.  The DataProvider interface provides a layer of abstraction to the DataConsumer, this clearly defines the contract that any implementation of a DataProvider must satisfy.  Creating a barrier in this fashion and using a mock object allows for creating isolated unit tests in a complex system.  The alternative would be setting up integration tests where an entire environment must be setup to test one particular component.&lt;br /&gt;
&lt;br /&gt;
Mock DataProviders could be configured with behavior and expectations for each test case that the DataConsumer need be tested against.  Some of the test cases may be when the DataProvider:&lt;br /&gt;
&lt;br /&gt;
*returns a faulty Data object&lt;br /&gt;
*returns a legitimate Data object&lt;br /&gt;
*returns null&lt;br /&gt;
*throws a DataRetrievalException&lt;br /&gt;
*throws an unchecked exception&lt;br /&gt;
&lt;br /&gt;
== Typical Steps to using a Mock Object Framework ==&lt;br /&gt;
=== Create the mock object ===&lt;br /&gt;
&lt;br /&gt;
This step involves creation of the mock object.  An example in Mockito:&lt;br /&gt;
&lt;br /&gt;
    Role mockRole = mock(Role.class);&lt;br /&gt;
&lt;br /&gt;
This declares a variable called Role which is a mock object of the Role class.  This variable is initialized to have the value mock(Role.class).  The mock method is a call to the Mockito framework which tells it to return a mock object of the Role class.&lt;br /&gt;
&lt;br /&gt;
=== Define the stubbed methods ===&lt;br /&gt;
This step involves defining what methods should do when they are called.  This step can be combined with the next step which is defining expectations.  An example in Flex Mock:&lt;br /&gt;
&lt;br /&gt;
    mockRole.should_receive(:getInt).times(3).&lt;br /&gt;
        and_return(10, 12, 14)&lt;br /&gt;
&lt;br /&gt;
One of the first things to notice here is how natural using the mock object framework feels here, it should be noted that many mock object frameworks strive for this type of readability.  Reading from left to right you can easily understand what is going on, &amp;quot;the mockRole object should receive getInt three times and return 10, 12, and 14&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Define the expectations ===&lt;br /&gt;
=== Execution of the test code ===&lt;br /&gt;
=== Verify the expectations were satisfied ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Mock_object&lt;br /&gt;
&lt;br /&gt;
2. http://onjava.com/pub/a/onjava/2004/02/11/mocks.html#Approaches&lt;br /&gt;
&lt;br /&gt;
3. http://msdn.microsoft.com/en-us/magazine/dd882516.aspx&lt;br /&gt;
&lt;br /&gt;
4. http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
*Java Mock Object Frameworks&lt;br /&gt;
**[http://mockito.org/ Mockito]&lt;br /&gt;
**[http://easymock.org/ EasyMock]&lt;br /&gt;
**[http://www.jmock.org/ JMock]&lt;br /&gt;
*Ruby Mock Object Frameworks&lt;br /&gt;
**[http://mocha.rubyforge.org/ Mocha]&lt;br /&gt;
**[http://flexmock.rubyforge.org/ Flex Mock]&lt;br /&gt;
&lt;br /&gt;
== Test 3 ==&lt;br /&gt;
== Test 4 ==&lt;br /&gt;
== Test 5 ==&lt;/div&gt;</summary>
		<author><name>3xT</name></author>
	</entry>
</feed>