Skip to content

Commit

Permalink
Merge branch 'master' into ckozak/gh172
Browse files Browse the repository at this point in the history
  • Loading branch information
olibye authored Mar 16, 2024
2 parents 0d8cf0f + 87d54c1 commit dc77d98
Show file tree
Hide file tree
Showing 31 changed files with 365 additions and 150 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: junit:junit
versions:
- 3.8.2
- 4.13.2
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Maven Build

on:
pull_request:
branches: [ "master" ]
merge_group:
types: [checks_requested]

jobs:
build:
name: Java ${{ matrix.java }} build
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: true
matrix:
java: [ 8, 11 ]
experimental: [false]
include:
- java: 17
experimental: true
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn --no-transfer-progress --batch-mode package --file pom.xml
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Maven deploy release
# Reset before repeated testing
# git push --delete origin 2.13.0
# git push -d origin release/2.13.0 release/2.13.0-snapshot
on:
push:
branches: [ "release/*" ]
jobs:
deploy:
# Avoid loops
if: github.event.commits[0].author.email != '[email protected]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Split branch into release version
env:
BRANCH: ${{ github.ref_name }}
id: split
run: echo "fragment=${BRANCH##*/}" >> $GITHUB_OUTPUT

- name: Configure git user
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions (run by ${{ github.actor }})"
- name: Maven set release version
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
GH_TOKEN: ${{ github.token }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
run: |
mvn --no-transfer-progress versions:set -DoldVersion=\* -DnewVersion=${{ steps.split.outputs.fragment }} -DgroupId=org.jmock -DgenerateBackupPoms=false
git add .
git commit --no-edit -m "Release version ${{ steps.split.outputs.fragment }}"
git tag -a -m "Release version ${{ steps.split.outputs.fragment }}" ${{ steps.split.outputs.fragment }}
mvn --no-transfer-progress --batch-mode deploy -P release
mvn versions:set -DoldVersion=* -DnextSnapshot=true -DgroupId=org.jmock -DgenerateBackupPoms=false
git checkout -b ${{ github.ref_name }}-snapshot
git add .
git commit --no-edit -m "Open development for next release"
git push origin ${{ github.ref_name }} HEAD --tags
gh pr create --repo jmock-developers/jmock-library -B master --title 'Merge ${{ github.ref_name }} back into master' --body 'Created by Github action'
27 changes: 27 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Maven deploy snapshot
on:
push:
branches: [ master ]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
server-id: ossrh
# used for signing the testjar
gpg-passphrase: secret
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD

- name: Publish package
run: mvn --no-transfer-progress --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.DEVELOPMENT
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export SONATYPE_USERNAME=UUU
export SONATYPE_PASSWORD=PPPP
mvn clean deploy -P release --settings settings.xml -Dgpg.keyname=XXXXXXXX

mvn versions:set -DoldVersion=* -DnewVersion=2.11.0-SNAPSHOT -DgroupId=org.jmock -DgenerateBackupPoms=false
mvn versions:set -DoldVersion=* -DnewVersion=2.13.0-SNAPSHOT -DgroupId=org.jmock -DgenerateBackupPoms=false

44 changes: 18 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
# JMock Library
[![Build Status](https://travis-ci.org/jmock-developers/jmock-library.svg?branch=jmock2)](https://travis-ci.org/jmock-developers/jmock-library)
[![Maven Build](https://github.com/jmock-developers/jmock-library/actions/workflows/build.yml/badge.svg)](https://github.com/jmock-developers/jmock-library/actions/workflows/build.yml)
[![Maven Central](https://img.shields.io/maven-central/v/org.jmock/jmock.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/org.jmock)

# Maven
```xml
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit5</artifactId>
<version>2.12.0</version>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
```
# Gradle

## Gradle 7 and Above

```gradle
testImplementation(
"junit:junit5:5.3.1",
"org.jmock:jmock-junit5:2.13.0"
)
```

## Gradle 6 and Below

```
testCompile(
"junit:junit5:5.3.1",
"org.jmock:jmock-junit5:2.12.0"
"org.jmock:jmock-junit5:2.13.0"
)
```
# Recent Changes
## 2.10.0
### JUnit 5 Support
- See https://github.com/jmock-developers/jmock-library/releases/tag/2.13.0

# JUnit 5 Support
* Swap @Rule JUnit4Mockery for @RegisterExtension JMock5Mockery
* Assign to a non-private JMock5Mockery or JUnit5 won't use it

Expand Down Expand Up @@ -49,27 +62,6 @@ public class JUnit5TestThatDoesSatisfyExpectations {
### JUnit 4 moved to provided scope in org.jmock:jmock
* This allows dependents to use other versions of junit or other test frameworks (e.g. junit 5)

### Java7 Support will be dropped next release

## 2.9.0
* Dropped JDK 6 compliance.
* Exposed the InvocationDispatcher so that ThreadingPolicies

## Upgrading to 2.8.X
Are you seeing NPEs?

We have had to make a breaking change to `with()`. Tests using `with(any(matcher))` for method signatures that require native types will throw `NullPointerException`.

You should change

oneOf(mock).methodWithIntParams(with(any(Integer.class)));

to the following

oneOf(mock).methodWithIntParams(with.intIs(anything());
This is due to a compiler change in Java 1.7. The 2.6.0 release was compiled with Java 1.6 so it did not suffer this problem.


# Advantages of jMock 2 over jMock 1
* Uses real method calls, not strings, so you can refactor more easily and
autocomplete in the IDE.
Expand Down
2 changes: 1 addition & 1 deletion jmock-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.12.0</version>
<version>2.13.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
43 changes: 43 additions & 0 deletions jmock-imposters-testdata/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.13.1-SNAPSHOT</version>
</parent>

<artifactId>jmock-imposters-testdata</artifactId>

<properties>
<scala.version>2.13.13</scala.version>
</properties>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.8.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jmock.testdata.scalaexample

case class BadlyAnnotated(@FieldOnly badlyAnnotated: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.jmock.testdata.scalaexample;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface FieldOnly {
}

8 changes: 7 additions & 1 deletion jmock-imposters-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.12.0</version>
<version>2.13.1-SNAPSHOT</version>
</parent>
<artifactId>jmock-imposters-tests</artifactId>

Expand Down Expand Up @@ -39,6 +39,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-imposters-testdata</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jmock.test.acceptance;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.api.Imposteriser;
import org.jmock.test.unit.lib.legacy.CodeGeneratingImposteriserParameterResolver;
import org.jmock.testdata.scalaexample.BadlyAnnotated;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

import static org.junit.Assert.assertSame;

public class BadAnnotationsAcceptanceTests {
Mockery context = new Mockery();

@ParameterizedTest
@ArgumentsSource(CodeGeneratingImposteriserParameterResolver.class)
public void shouldMockScalaCaseClassWithFieldAnnotationOnParameter(Imposteriser imposteriser) {
context.setImposteriser(imposteriser);

final BadlyAnnotated mock = context.mock(BadlyAnnotated.class);
final String result = "a mock result";
context.checking(new Expectations() {
{
oneOf(mock).badlyAnnotated();
will(returnValue(result));
}
});

assertSame(mock.badlyAnnotated(), result);
}
}
2 changes: 1 addition & 1 deletion jmock-imposters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.12.0</version>
<version>2.13.1-SNAPSHOT</version>
</parent>
<artifactId>jmock-imposters</artifactId>
<description>Class mocks are more numerous than interface mocks, so drop the legacy name</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import net.bytebuddy.dynamic.scaffold.TypeValidation;
import org.jmock.api.Imposteriser;
import org.jmock.api.Invocation;
import org.jmock.api.Invokable;
Expand Down Expand Up @@ -134,6 +135,7 @@ static public Object intercept(
private Class<?> proxyClass(final Invokable mockObject, final Class<?> mockedType, Class<?>... ancilliaryTypes)
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Builder<?> builder = new ByteBuddy()
.with(TypeValidation.DISABLED)
.with(new NamingStrategy.SuffixingRandom(JMOCK_KEY, JMOCK_KEY.toLowerCase()))
.subclass(mockedType)
.implement(ancilliaryTypes)
Expand Down
Loading

0 comments on commit dc77d98

Please sign in to comment.