Skip to content

FISH-7252 Update Mockito dependency version to 5.16.1 #7261

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

Merged
merged 3 commits into from
Apr 4, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2021-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -40,23 +40,27 @@
package com.sun.ejb.containers;

import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.MockitoAnnotations;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class BaseContainerTest extends TestCase {
public class BaseContainerTest {

@Mock
private EJBContextImpl ejbContextImpl;

@Mock
private BaseContainer baseContainer;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void createEmptyContextAndInterceptorsWithoutNullPointerExceptionTest() throws Exception {
boolean thrownExceptionFlag = false;
Expand All @@ -68,7 +72,7 @@ public void createEmptyContextAndInterceptorsWithoutNullPointerExceptionTest() t
} catch(NullPointerException e) {
thrownExceptionFlag = true;
}
assertFalse(thrownExceptionFlag);
Assert.assertFalse(thrownExceptionFlag);
verify(baseContainer, times(1)).createEmptyContextAndInterceptors(ejbContextImpl);
}

Expand All @@ -84,7 +88,7 @@ public void interceptMethodWithoutNullPointerExceptionTest() throws Throwable{
thrownExceptionFlag = true;
}

assertFalse(thrownExceptionFlag);
Assert.assertFalse(thrownExceptionFlag);
verify(baseContainer, times(1)).intercept(LifecycleCallbackDescriptor.CallbackType.AROUND_CONSTRUCT,
ejbContextImpl);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020-2021 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2020-2025 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -43,11 +43,11 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import jakarta.annotation.sql.DataSourceDefinition;
import org.mockito.MockitoAnnotations;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -57,14 +57,14 @@
* Test for DataSourceDefinition processing in DataSourceDefinitionHandler
* @author jonathan coustick
*/
@RunWith(MockitoJUnitRunner.class)
public class DataSourceDefinitionTest {

@Mock
private DataSourceDefinition dataSourceDefinition;

@Before
public void before() {
MockitoAnnotations.initMocks(this);
when(dataSourceDefinition.portNumber()).thenReturn(-1);
when(dataSourceDefinition.isolationLevel()).thenReturn(-1);
when(dataSourceDefinition.transactional()).thenReturn(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2019-2025 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -43,17 +43,15 @@

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.MockitoAnnotations;

import static java.util.Arrays.asList;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class HazelcastTimerStoreTest extends HazelcastTimerStoreTestBase {
@Mock
private HZTimer timer1, timer2, timer3;
Expand All @@ -62,6 +60,7 @@ public class HazelcastTimerStoreTest extends HazelcastTimerStoreTestBase {

@Before
public void setUpTimers() {
MockitoAnnotations.initMocks(this);
timers = asList(timer1, timer2, timer3);
when(timer1.getMemberName()).thenReturn("jb");
when(timer2.getMemberName()).thenReturn("hz");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2020-2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2020-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -54,12 +54,10 @@

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.MockitoAnnotations;

@RunWith(MockitoJUnitRunner.class)
public class HashiCorpSecretsConfigSourceTest {
private static final String FAKE_TOKEN = "FAKE_TOKEN";
private static final String FAKE_SECRETS_ENGINE_PATH = "KV";
Expand All @@ -77,6 +75,7 @@ public class HashiCorpSecretsConfigSourceTest {

@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
// Configure the vault token
configSource.hashiCorpVaultToken = FAKE_TOKEN;
configSource.secretsEnginePath = FAKE_SECRETS_ENGINE_PATH;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2021-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -41,12 +41,12 @@

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
Expand All @@ -64,7 +64,6 @@
import static fish.payara.security.client.PayaraConstants.REST_CLIENT_CERTIFICATE_ALIAS;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class RestClientSslContextAliasListenerTest {

@Mock
Expand All @@ -81,6 +80,11 @@ public class RestClientSslContextAliasListenerTest {
private RestClientSslContextAliasListener restClientSslContextAliasListener =
new RestClientSslContextAliasListener();

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void restClientAliasPropertySslContextTest() throws Exception {
KeyManager[] managers = getManagers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2019-2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2019-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -46,16 +46,14 @@

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import fish.payara.cluster.Clustered;
import org.mockito.MockitoAnnotations;

/**
* @author Matt Gill
*/
@RunWith(MockitoJUnitRunner.class)
public class ClusterScopeContextTest {

private static final String ANNOTATION_BEAN_NAME = "Annotation";
Expand All @@ -70,6 +68,7 @@ public class ClusterScopeContextTest {

@Before
public void initialiseMocks() {
MockitoAnnotations.initMocks(this);
when(annotation.keyName()).thenReturn(ANNOTATION_BEAN_NAME);
when(bean.getName()).thenReturn(CDI_BEAN_NAME);
when(bean.getBeanClass()).thenReturn(BEAN_CLASS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021-2022] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2021-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -39,25 +39,25 @@
*/
package org.apache.catalina.core;

import junit.framework.TestCase;
import org.apache.catalina.HttpRequest;
import org.apache.catalina.HttpResponse;
import org.glassfish.grizzly.http.util.DataChunk;
import org.glassfish.web.valve.GlassFishValve;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.mockito.MockitoAnnotations;

import java.io.IOException;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class StandardContextValveTest extends TestCase {
public class StandardContextValveTest {

@Mock
private HttpRequest httpRequest;
Expand All @@ -71,6 +71,11 @@ public class StandardContextValveTest extends TestCase {
@InjectMocks
private StandardContextValve standardContextValve = new StandardContextValve();

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void preventAccessToRestrictedDirectoryWithEmptyContextRootTest() throws IOException, ServletException {
DataChunk dataChunkURL1 = DataChunk.newInstance();
Expand Down Expand Up @@ -101,28 +106,28 @@ public void normalizeURLTest() {

String result = standardContextValve.normalize(path1);

assertEquals("/my.jsp", result);
Assert.assertEquals("/my.jsp", result);

result = standardContextValve.normalize(path2);

assertEquals("/app/some/something/my.jsp", result);
Assert.assertEquals("/app/some/something/my.jsp", result);

result = standardContextValve.normalize(path3);

assertEquals("/my.jsp", result);
Assert.assertEquals("/my.jsp", result);

result = standardContextValve.normalize(path4);

assertEquals("/WEB-INF", result);
Assert.assertEquals("/WEB-INF", result);

result = standardContextValve.normalize(path5);

assertEquals("/META-INF", result);
Assert.assertEquals("/META-INF", result);
}

protected void verifyThatResourceIsNotFound(int pipelineResult, int times, HttpRequest httpRequest, HttpResponse httpResponse,
HttpServletResponse httpServletResponse) throws IOException {
assertEquals(GlassFishValve.END_PIPELINE, pipelineResult);
Assert.assertEquals(GlassFishValve.END_PIPELINE, pipelineResult);
verify(httpRequest, times(times)).getCheckRestrictedResources();
verify(httpRequest, times(times)).getRequestPathMB();
verify(httpResponse, times(times)).getResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2020] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2020-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -43,26 +43,23 @@
import java.util.Vector;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.Mockito;

import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class FilterDefDecoratorTest {
@Mock
private ServletFilter filter;

@Test
public void nullAsyncSupportedFlagShallNotCauseException() {
ServletFilter filter = Mockito.mock(ServletFilter.class);
when(filter.isAsyncSupported()).thenReturn(null);
when(filter.getInitializationParameters()).thenReturn(new Vector());

FilterDefDecorator fdd = new FilterDefDecorator(filter);

assertFalse(fdd.isAsyncSupported());
}

}

Loading