%bcond_with bootstrap

Name:           mockito
Version:        5.8.0
Release:        1
Summary:        Tasty mocking framework for unit tests in Java
License:        MIT
URL:            https://site.mockito.org/
BuildArch:      noarch

# ./generate-tarball.sh
Source0:        %{name}-%{version}.tar.gz
Source1:        generate-tarball.sh
# A custom build script to allow building with maven instead of gradle
Source2:        aggregator.pom
# Maven central POMs for subprojects
Source3:        https://repo1.maven.org/maven2/org/mockito/mockito-core/%{version}/mockito-core-%{version}.pom
Source4:        https://repo1.maven.org/maven2/org/mockito/mockito-junit-jupiter/%{version}/mockito-junit-jupiter-%{version}.pom

# Mockito expects byte-buddy to have a shaded/bundled version of ASM, but
# we don't bundle in Fedora, so this patch makes mockito use ASM explicitly
Patch:          use-unbundled-asm.patch

%if %{with bootstrap}
BuildRequires:  javapackages-bootstrap
%else
BuildRequires:  maven-local
BuildRequires:  mvn(junit:junit)
BuildRequires:  mvn(net.bytebuddy:byte-buddy)
BuildRequires:  mvn(net.bytebuddy:byte-buddy-agent)
BuildRequires:  mvn(net.bytebuddy:byte-buddy-dep)
BuildRequires:  mvn(org.apache.maven.plugins:maven-antrun-plugin)
BuildRequires:  mvn(org.junit.jupiter:junit-jupiter-api)
BuildRequires:  mvn(org.objenesis:objenesis)
BuildRequires:  mvn(org.opentest4j:opentest4j)
%endif

%description
Mockito is a mocking framework that tastes really good. It lets you write
beautiful tests with clean & simple API. Mockito doesn't give you hangover
because the tests are very readable and they produce clean verification
errors.

%package javadoc
Summary:        API documentation for %{name}

%description javadoc
API documentation for %{name}.

%package junit-jupiter
Summary:        Mockito JUnit 5 support
Requires:       %{name} = %{version}-%{release}

%description junit-jupiter
Mockito JUnit 5 support.

%prep
%autosetup -p1

cp %{SOURCE2} aggregator.pom
cp %{SOURCE3} pom.xml
cp %{SOURCE4} subprojects/junit-jupiter/pom.xml

# Disable failing test
# TODO check status: https://github.com/mockito/mockito/issues/2162
sed -i '/add_listeners_concurrently_sanity_check/i @org.junit.Ignore' src/test/java/org/mockitousage/debugging/StubbingLookupListenerCallbackTest.java

# Workaround easymock incompatibility with Java 17 that should be fixed
# in easymock 4.4: https://github.com/easymock/easymock/issues/274
%pom_add_plugin :maven-surefire-plugin . "<configuration>
    <argLine>--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED</argLine></configuration>"

# Compatibility alias
%mvn_alias org.%{name}:%{name}-core org.%{name}:%{name}-all

%pom_add_dep junit:junit
%pom_add_dep net.bytebuddy:byte-buddy-dep
%pom_remove_dep org.objenesis:objenesis
%pom_add_dep org.objenesis:objenesis
%pom_add_dep org.opentest4j:opentest4j

%pom_remove_dep org.junit.jupiter:junit-jupiter-api subprojects/junit-jupiter
%pom_add_dep org.junit.jupiter:junit-jupiter-api subprojects/junit-jupiter

mkdir -p src/main/resources/mockito-extensions
echo 'member-accessor-module' > src/main/resources/mockito-extensions/org.mockito.plugins.MemberAccessor
echo 'mock-maker-subclass' > src/main/resources/mockito-extensions/org.mockito.plugins.MockMaker

# see gradle/mockito-core/inline-mock.gradle
%pom_xpath_inject 'pom:project/pom:build/pom:plugins' '
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>any</version>
  <executions>
    <execution>
      <phase>process-classes</phase>
      <configuration>
        <target>
          <copy file="${project.build.outputDirectory}/org/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher.class"
            tofile="${project.build.outputDirectory}/org/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher.raw"/>
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>any</version>
  <configuration>
    <excludes>
      <exclude>org/mockito/internal/creation/bytebuddy/inject/*.class</exclude>
    </excludes>
  </configuration>
</plugin>
'

%mvn_package :aggregator __noinstall

%build
%mvn_build -f -- -Dmaven.compiler.release=11 -Dproject.build.sourceEncoding=UTF-8 -f aggregator.pom

%mvn_package org.mockito:mockito-junit-jupiter junit-jupiter

%install
%mvn_install

%files -f .mfiles
%license LICENSE
%doc README.md doc/design-docs/custom-argument-matching.md

%files javadoc -f .mfiles-javadoc
%license LICENSE

%files junit-jupiter -f .mfiles-junit-jupiter

%changelog
* Wed Feb 04 2026 yaoxin <1024769339@qq.com> - 5.8.0-1
- Update to 5.8.0

* Tue Jul 29 2025 yaoxin <1024769339@qq.com> - 3.12.4-1
- Update to 3.12.4

* Mon Apr 28 2025 Ge Wang <wang__ge@126.com> - 3.3.3-1
- update to version 3.3.3

* Fri Nov 11 2022 xu_ping <xuping33@h-partners.com> - 2.23.9-3
- change source and url

* Thu Jun 23 2022 Ge Wang <wangge20@h-partners.com> - 2.23.9-2
- ignore test failure 

* Mon Aug 17 2020 wangyue <wangyue92@huawei.com> - 2.23.9-1
- upgrade the version to 2.23.9

* Thu Apr 23 2020 wutao <wutao61@huawei.com> 1.10.19-19
* delete useless patches

* Thu Apr 2 2020 gulining <gulining1@huawei.com> - 1.10.19-18
- Package init