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

Feature/jenkins 66322 prepare for upgraded guava #7

Merged
merged 4 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
JENKINS-66322: compatibility with java 11
  • Loading branch information
simschla committed Aug 20, 2021
commit 8b851541bc84e2f4133f2b830b4567d4414278a5
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.3</version>
<version>4.24</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -59,7 +59,6 @@
</issueManagement>

<properties>
<powermock.version>1.6.1</powermock.version>
<jenkins.version>2.222.1</jenkins.version>
<java.level>8</java.level>
</properties>
Expand All @@ -78,16 +77,24 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* The MIT License
*
*
* Copyright (c) 2011, Erik Ramfelt
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -29,35 +29,44 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.doReturn;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest(User.class)
@PowerMockIgnore({"jdk.xml.internal.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
public class UserGravatarResolverTest {

@Mock
User user;

@Mock
Mailer.UserProperty mailPropertyOfUser;

@Mock
GravatarUrlCreator urlCreator;

@Spy
UserGravatarResolver resolver = new UserGravatarResolver();
UserGravatarResolver resolver;

@Before
public void setUp() {
user = PowerMockito.mock(User.class);
mailPropertyOfUser = PowerMockito.mock(Mailer.UserProperty.class);
urlCreator = PowerMockito.mock(GravatarUrlCreator.class);
resolver = PowerMockito.spy(new UserGravatarResolver());

@Before
public void setUp() {
when(user.getId()).thenReturn("user");
when(user.getProperty(same(Mailer.UserProperty.class))).thenReturn(mailPropertyOfUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@
import com.google.common.testing.EqualsTester;
import hudson.model.User;
import hudson.tasks.Mailer;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Collections;

import static java.util.Collections.emptyMap;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest(User.class)
@PowerMockIgnore({"jdk.xml.internal.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
public class GravatarUserTest {

public static final String EMAIL = "myid@mail.com";
public static final String USER_ID = "myid";
@Mock

User user;

@Mock
Mailer.UserProperty mailProperty;

@Before
public void setUp() throws Exception {
user = PowerMockito.mock(User.class);
when(user.getId()).thenReturn(USER_ID);

mailProperty = PowerMockito.mock(Mailer.UserProperty.class);
when(mailProperty.getAddress()).thenReturn(EMAIL);

PowerMockito.mockStatic(User.class);
when(User.get(eq(USER_ID))).thenReturn(user);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public void itShouldOnlyCallEMailPropertyOnce() throws Exception {
grUser.emailAddress();
grUser.emailAddress();
grUser.emailAddress();
verify(user, times(1)).getProperty(Mailer.UserProperty.class);
Mockito.verify(user, Mockito.times(1)).getProperty(Mailer.UserProperty.class);
}

@Test
Expand All @@ -105,7 +105,7 @@ public void itShouldBehaveCorrectlyWithEquals() throws Exception {
}

private GravatarUser user(String userId) {
User user = mock(User.class);
User user = PowerMockito.mock(User.class);
when(user.getId()).thenReturn(userId);
return GravatarUser.gravatarUser(user);
}
Expand Down