Updated POM to show build numbers and updated test class

This commit is contained in:
tastybento 2019-08-11 12:51:14 -07:00
parent 43bc50687c
commit 18c7ee5e0d
4 changed files with 262 additions and 180 deletions

407
pom.xml
View File

@ -6,13 +6,24 @@
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>warps</artifactId> <artifactId>warps</artifactId>
<version>1.5.2-SNAPSHOT</version> <version>${revision}</version>
<name>WelcomeWarpSigns</name> <name>WelcomeWarpSigns</name>
<description>WelcomeWarpSigns is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.</description> <description>WelcomeWarpSigns is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.</description>
<url>https://github.com/BentoBoxWorld/addon-welcomewarpsigns</url> <url>https://github.com/BentoBoxWorld/addon-welcomewarpsigns</url>
<inceptionYear>2018</inceptionYear> <inceptionYear>2018</inceptionYear>
<developers>
<developer>
<id>tastybento</id>
<email>tastybento@bentobox.world</email>
<timezone>-8</timezone>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
</developers>
<scm> <scm>
<connection>scm:git:https://github.com/BentoBoxWorld/addon-welcomewarpsigns.git</connection> <connection>scm:git:https://github.com/BentoBoxWorld/addon-welcomewarpsigns.git</connection>
<developerConnection>scm:git:git@github.com:BentoBoxWorld/addon-welcomewarpsigns.git</developerConnection> <developerConnection>scm:git:git@github.com:BentoBoxWorld/addon-welcomewarpsigns.git</developerConnection>
@ -41,12 +52,89 @@
</distributionManagement> </distributionManagement>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version> <!-- Non-minecraft related dependencies -->
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.6.0-SNAPSHOT</bentobox.version>
<level.version>1.5.0</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.6.0</build.version>
</properties> </properties>
<!-- Profiles will allow to automatically change build version. -->
<profiles>
<profile>
<!-- ci profile is activated if exist environment variable BUILD_NUMBER. -->
<!-- It replaces ${build.number} that is currently '-LOCAL' with
correct build number from JENKINS machine. -->
<id>ci</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<build.number>-b${env.BUILD_NUMBER}</build.number>
</properties>
</profile>
<profile>
<!-- Master profile is activated if exist environment variable
GIT_BRANCH and its value is origin/master. -->
<!-- It will replace 'revision' with '${build.version}' so it
removes '-SNAPSHOT' string at the end. -->
<!-- Also, as this is release build, build number can be set
to empty string. -->
<!-- This profile will be used only if exist environment variable
GIT_BRANCH with value origin/master. -->
<id>master</id>
<activation>
<property>
<name>env.GIT_BRANCH</name>
<value>origin/master</value>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<revision>${build.version}</revision>
<!-- Empties build number variable. -->
<build.number></build.number>
</properties>
</profile>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>tastybento-github</sonar.organization>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.1.1168</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
@ -63,44 +151,57 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <!-- Spigot API -->
<groupId>org.spigotmc</groupId> <dependency>
<artifactId>spigot-api</artifactId> <groupId>org.spigotmc</groupId>
<version>1.14.1-R0.1-SNAPSHOT</version> <artifactId>spigot-api</artifactId>
<scope>provided</scope> <version>${spigot.version}</version>
</dependency> <scope>provided</scope>
<dependency> </dependency>
<groupId>org.mockito</groupId> <!-- Mockito (Unit testing) -->
<artifactId>mockito-all</artifactId> <dependency>
<version>1.10.19</version> <groupId>org.mockito</groupId>
<scope>test</scope> <artifactId>mockito-core</artifactId>
</dependency> <version>3.0.0</version>
<dependency> <scope>test</scope>
<groupId>org.powermock</groupId> </dependency>
<artifactId>powermock-module-junit4</artifactId> <dependency>
<version>${powermock.version}</version> <groupId>org.powermock</groupId>
<scope>test</scope> <artifactId>powermock-module-junit4</artifactId>
</dependency> <version>${powermock.version}</version>
<dependency> <scope>test</scope>
<groupId>org.powermock</groupId> </dependency>
<artifactId>powermock-api-mockito</artifactId> <dependency>
<version>${powermock.version}</version> <groupId>org.powermock</groupId>
<scope>test</scope> <artifactId>powermock-api-mockito2</artifactId>
</dependency> <version>${powermock.version}</version>
<dependency> <scope>test</scope>
<groupId>world.bentobox</groupId> </dependency>
<artifactId>bentobox</artifactId> <dependency>
<version>1.5.0</version> <groupId>world.bentobox</groupId>
</dependency> <artifactId>bentobox</artifactId>
<version>${bentobox.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>level</artifactId> <artifactId>level</artifactId>
<version>1.5.0</version> <version>${level.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<!-- By default ${revision} is ${build.version}-SNAPSHOT -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will
be only ${build.version}. -->
<!-- By default ${build.number} is -LOCAL. -->
<!-- If the BUILD_NUMBER variable is set, then it will be -b[number]. -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will
be the empty string. -->
<finalName>${project.name}-${revision}${build.number}</finalName>
<defaultGoal>clean package</defaultGoal> <defaultGoal>clean package</defaultGoal>
<resources> <resources>
<resource> <resource>
@ -113,134 +214,112 @@
<filtering>false</filtering> <filtering>false</filtering>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version> <version>3.7.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version> <version>2.22.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
<configuration> <configuration>
<show>public</show> <show>public</show>
<failOnError>false</failOnError> <failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption> <additionalJOption>-Xdoclint:none</additionalJOption>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<id>attach-javadocs</id> <id>attach-javadocs</id>
<goals> <goals>
<goal>jar</goal> <goal>jar</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>
<goals> <goals>
<goal>jar-no-fork</goal> <goal>jar-no-fork</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version> <version>3.1.1</version>
<configuration> <configuration>
<minimizeJar>false</minimizeJar> <minimizeJar>false</minimizeJar>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId> <artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version> <version>2.5.2</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId> <artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version> <version>2.8.2</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version> <version>0.8.3</version>
<configuration> <configuration>
<append>true</append> <append>true</append>
</configuration> <excludes>
<executions> <!-- This is required to prevent Jacoco from adding synthetic fields
<execution> to a JavaBean class (causes errors in testing) -->
<id>pre-unit-test</id> <exclude>**/*Names*</exclude>
<goals> </excludes>
<goal>prepare-agent</goal> </configuration>
</goals> <executions>
</execution> <execution>
<execution> <id>pre-unit-test</id>
<id>post-unit-test</id> <goals>
<goals> <goal>prepare-agent</goal>
<goal>report</goal> </goals>
</goals> </execution>
</execution> <execution>
</executions> <id>post-unit-test</id>
</plugin> <goals>
</plugins> <goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> </build>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>bentobox-world</sonar.organization>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -1,6 +1,6 @@
name: WelcomeWarps name: WelcomeWarps
main: world.bentobox.warps.Warp main: world.bentobox.warps.Warp
version: ${version} version: ${version}${build.number}
authors: tastybento authors: tastybento

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.warps; package world.bentobox.warps;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -26,6 +23,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -39,18 +37,24 @@ import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.warps.config.Settings; import world.bentobox.warps.config.Settings;
/** /**
* @author ben * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class}) @PrepareForTest({Bukkit.class})
public class WarpPanelManagerTest { public class WarpPanelManagerTest {
@Mock
private WarpSignsManager wsm; private WarpSignsManager wsm;
@Mock
private Warp addon; private Warp addon;
@Mock
private Player player; private Player player;
@Mock
private User user; private User user;
@Mock
private World world; private World world;
@Mock
private Inventory top; private Inventory top;
private UUID uuid; private UUID uuid;
@ -59,8 +63,6 @@ public class WarpPanelManagerTest {
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
addon = mock(Warp.class);
wsm = mock(WarpSignsManager.class);
when(addon.getWarpSignsManager()).thenReturn(wsm); when(addon.getWarpSignsManager()).thenReturn(wsm);
// Fill with 200 fake warps (I'm banking on them all being different, but there could be a clash) // Fill with 200 fake warps (I'm banking on them all being different, but there could be a clash)
List<UUID> list = new ArrayList<>(); List<UUID> list = new ArrayList<>();
@ -73,18 +75,15 @@ public class WarpPanelManagerTest {
when(wsm.getSortedWarps(any())).thenReturn(list); when(wsm.getSortedWarps(any())).thenReturn(list);
user = mock(User.class); // User and player
player = mock(Player.class);
when(user.getPlayer()).thenReturn(player); when(user.getPlayer()).thenReturn(player);
when(user.getTranslation(Mockito.anyVararg())).thenAnswer(new Answer<String>() { when(user.getTranslation(Mockito.any())).thenAnswer(new Answer<String>() {
@Override @Override
public String answer(InvocationOnMock invocation) throws Throwable { public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgumentAt(0, String.class); return invocation.getArgument(0, String.class);
}}); }});
// World
world = mock(World.class);
// BentoBox // BentoBox
BentoBox plugin = mock(BentoBox.class); BentoBox plugin = mock(BentoBox.class);
@ -100,7 +99,7 @@ public class WarpPanelManagerTest {
when(itemF.getItemMeta(any())).thenReturn(imeta); when(itemF.getItemMeta(any())).thenReturn(imeta);
when(Bukkit.getItemFactory()).thenReturn(itemF); when(Bukkit.getItemFactory()).thenReturn(itemF);
top = mock(Inventory.class); // Inventory
when(top.getSize()).thenReturn(9); when(top.getSize()).thenReturn(9);
when(Bukkit.createInventory(any(), Mockito.anyInt(), any())).thenReturn(top); when(Bukkit.createInventory(any(), Mockito.anyInt(), any())).thenReturn(top);

View File

@ -51,6 +51,10 @@ import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.warps.config.Settings; import world.bentobox.warps.config.Settings;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, Util.class, NamespacedKey.class, Tag.class}) @PrepareForTest({Bukkit.class, Util.class, NamespacedKey.class, Tag.class})
public class WarpSignsListenerTest { public class WarpSignsListenerTest {
@ -133,7 +137,7 @@ public class WarpSignsListenerTest {
@Override @Override
public String answer(InvocationOnMock invocation) throws Throwable { public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgumentAt(1, String.class); return invocation.getArgument(1, String.class);
}}); }});
when(plugin.getLocalesManager()).thenReturn(lm); when(plugin.getLocalesManager()).thenReturn(lm);
@ -160,7 +164,7 @@ public class WarpSignsListenerTest {
when(Util.getWorld(any())).thenReturn(world); when(Util.getWorld(any())).thenReturn(world);
// Locales // Locales
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class); Answer<String> answer = invocation -> invocation.getArgument(1, String.class);
when(lm.get(any(User.class), anyString())).thenAnswer(answer); when(lm.get(any(User.class), anyString())).thenAnswer(answer);
when(plugin.getLocalesManager()).thenReturn(lm); when(plugin.getLocalesManager()).thenReturn(lm);