Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmockito property update for real class #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Lists which files git can ignore (ie. can be safely deleted and will
# not be shown as tracked with "git status").

# Backup files
*~
*.asv
# Lists which files git can ignore (ie. can be safely deleted and will
# not be shown as tracked with "git status").

# Backup files
*~
*.asv
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
47 changes: 1 addition & 46 deletions README
Original file line number Diff line number Diff line change
@@ -1,46 +1 @@
mmockito - MATLAB mock framework based on Java Mockito

The latest version can always be downloaded from Github:

https://github.com/vperic/mmockito

The project mailing list can be found on Google Groups:

https://groups.google.com/forum/#!forum/mmockito

mmockito is distributed under the BSD license. All contributions are
welcome!

Issues can be reported on the projects' Github page; code should also be
submitted as pull requests. Pull requests should include the
necessary tests; tests should be passing at all times.

Usage
=====

The 'mmockito' directory should be added to MATLAB's path; it contains the most
used classes. The main functionality is provided by the "Mock" class, which
supports both stubbing and verification. In-order verification is provided by
the "InOrder" class. The "Matcher" class is an interface for specifying
argument matchers, "Any", "ArgThat" and "AnyArgs" are commonly used matchers.
Some further matchers are provided in the mmockito.matchers package. The
mmockito.internal package has internal class which should not be used by
end-users.

For more detailed information consult the help files of individual classes.

More documentation, including a detailed overview of features and
comparison to Java Mockito, are available in my bachelor's thesis:

http://cyber.felk.cvut.cz/research/theses/detail.phtml?id=407

Tests
=====

To run tests, use the runtests function, which returns a TestResult object:

r = runtests('all');

Other options are 'acceptance', 'unit', or the exact name of a unit test file.

MATLAB 2013a or higher is required to run the tests.
Documentation and usage examples for mmockito.
1 change: 0 additions & 1 deletion docs/README

This file was deleted.

1 change: 0 additions & 1 deletion mmockito/README

This file was deleted.

58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.ragavsathish</groupId>
<artifactId>mmockito</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<connection>scm:git:git@github.com:ragavsathish/mmockito.git</connection>
<url>scm:git:git@github.com:ragavsathish/mmockito.git</url>
<developerConnection>scm:git:git@github.com:ragavsathish/mmockito.git</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/bin.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>unpack-lib</id>
<phase>process-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>
22 changes: 0 additions & 22 deletions runtests.m

This file was deleted.

23 changes: 23 additions & 0 deletions src/assembly/bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/matlab</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>./</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>./</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
classdef ArgEqualTo < Matcher
%ArgEqualTo is an internal matcher used to match constants.
% If constants are passed to be matched, they need to be converted to
% a Matcher. The robust solution would be to reuse the IsEqualTo
% constraint from the new matlab.unittest module, but it is not
% available in earlier MATLAB versions. In those cases, fallback to a
% simpler Matcher which works only with primitive types.

% Implemented as a try/catch rather than a version check because the
% former is much faster; using a version check in both methods
% approximately tripled the test time.

properties
expected;

matcher;
end

methods
function self = ArgEqualTo(expected)
try
import matlab.unittest.constraints.*;
self.matcher = ArgThat(IsEqualTo(expected));
catch
if isa(expected, 'numeric') || isa(expected, 'char')
self.expected = expected;
else
ME = MException('mmockito:illegalMatcher', ...
'Matching constants (other than primitive types) is not supported under MATLAB older than 2013a. Please update or use a custom Matcher.');
throw(ME);
end;
end;
end;

function answer = matches(self, actual)
try
answer = matches(self.matcher, actual);
catch
if isa(self.expected, char)
answer = strcmp(self.expected, actual);
else % numeric
answer = eq(self.expected, actual);
end;
end;
end;
end

end

classdef ArgEqualTo < Matcher
%ArgEqualTo is an internal matcher used to match constants.
% If constants are passed to be matched, they need to be converted to
% a Matcher. The robust solution would be to reuse the IsEqualTo
% constraint from the new matlab.unittest module, but it is not
% available in earlier MATLAB versions. In those cases, fallback to a
% simpler Matcher which works only with primitive types.
% Implemented as a try/catch rather than a version check because the
% former is much faster; using a version check in both methods
% approximately tripled the test time.
properties
expected;
matcher;
end
methods
function self = ArgEqualTo(expected)
try
import matlab.unittest.constraints.*;
self.matcher = ArgThat(IsEqualTo(expected));
catch
if isa(expected, 'numeric') || isa(expected, 'char')
self.expected = expected;
else
ME = MException('mmockito:illegalMatcher', ...
'Matching constants (other than primitive types) is not supported under MATLAB older than 2013a. Please update or use a custom Matcher.');
throw(ME);
end;
end;
end;
function answer = matches(self, actual)
try
answer = matches(self.matcher, actual);
catch
if isa(self.expected, char)
answer = strcmp(self.expected, actual);
else % numeric
answer = eq(self.expected, actual);
end;
end;
end;
end
end
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
classdef Invocation
%Invocation holds the two substruct which define a method invocation
% The two substruct are enough to define an arbitrary method call.
% Invocation is a value class, there is no difference between two
% Invocations created with the same substructs. The class only has a
% constructor which checks if we defined a valid method call.
%
% S(1).type = '.' we only mock functions
% S(1).subs = '...' the function name we are mocking
%
% S(2).type = '()' functions are only called with round brackets
% S(2).subs call arguments, can be anything


properties
S;
end

methods
function obj = Invocation(S)
if S(1).type ~= '.'
ME = MException('mmockito:illegalInvocation', ...
'Must call a function on the mock object');
throw(ME);
end;

if S(2).type == '.'
ME = MException('mmockito:illegalInvocation', ...
'A function must be called with round brackets.');
throw(ME);
end;

obj.S = S;
end;

end

end

classdef Invocation
%Invocation holds the two substruct which define a method invocation
% The two substruct are enough to define an arbitrary method call.
% Invocation is a value class, there is no difference between two
% Invocations created with the same substructs. The class only has a
% constructor which checks if we defined a valid method call.
%
% S(1).type = '.' we only mock functions
% S(1).subs = '...' the function name we are mocking
%
% S(2).type = '()' functions are only called with round brackets
% S(2).subs call arguments, can be anything
properties
S;
end
methods
function obj = Invocation(S)
if S(1).type ~= '.'
ME = MException('mmockito:illegalInvocation', ...
'Must call a function on the mock object');
throw(ME);
end;
if S(2).type == '.'
ME = MException('mmockito:illegalInvocation', ...
'A function must be called with round brackets.');
throw(ME);
end;
obj.S = S;
end;
end
end
Loading