Updated to FC-0.9

Moved folders to match Maven layout.

Added LevelPresenterTest class.
This commit is contained in:
tastybento 2018-08-09 06:34:35 +09:00
parent d70a4bf9b7
commit 60ec40830c
6 changed files with 290 additions and 52 deletions

247
pom.xml
View File

@ -1,55 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>bskyblock.addon</groupId>
<artifactId>Level</artifactId> <artifactId>Level</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BentoBox Level</name>
<description>Level is an add-on for BentoBox that calculates a level score for islands in BSkyBlock or AcidIsland worlds.</description>
<url>https://github.com/BentoBoxWorld/addon-level</url>
<inceptionYear>2018</inceptionYear>
<scm>
<connection>scm:git:https://github.com/BentoBoxWorld/addon-level.git</connection>
<developerConnection>scm:git:git@github.com:BentoBoxWorld/addon-level.git</developerConnection>
<url>https://github.com/BentoBoxWorld/addon-level</url>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/BentoBoxWorld/addon-Level/issues</url>
</issueManagement>
<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>
<java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version>
</properties> </properties>
<build>
<defaultGoal>clean package install</defaultGoal>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}</directory>
<includes>
<include>*.yml</include>
</includes>
</resource>
<resource>
<targetPath>locales</targetPath>
<filtering>false</filtering>
<directory>${basedir}/locales</directory>
<includes>
<include>*.yml</include>
</includes>
</resource>
</resources>
<plugins> <repositories>
<plugin> <repository>
<artifactId>maven-compiler-plugin</artifactId> <id>spigot-repo</id>
<version>3.5.1</version> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
<configuration> </repository>
<source>1.8</source> </repositories>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version> <version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<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>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId> <artifactId>bentobox</artifactId>
<version>FC-0.81</version> <version>FC-0.9</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -59,11 +76,149 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<repositories>
<repository> <build>
<id>spigot-repo</id> <defaultGoal>clean package</defaultGoal>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <resources>
</repository> <resource>
</repositories> <directory>src/main/resources</directory>
<groupId>bskyblock.addon</groupId> <filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/locales</directory>
<targetPath>./locales</targetPath>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<show>private</show>
<failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<minimizeJar>false</minimizeJar>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>tastybento-github</sonar.organization>
<sonar.exclusions>**/Metrics.java</sonar.exclusions>
</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

@ -101,12 +101,6 @@ public class Level extends Addon {
@Override @Override
public void onEnable() { public void onEnable() {
// Check if it is enabled - it might be loaded, but not enabled.
if (getPlugin() == null || !getPlugin().isEnabled()) {
getLogger().severe("BentoBox does not exist or is not enabled. Stopping.");
this.setEnabled(false);
return;
}
// Load the plugin's config // Load the plugin's config
settings = new Settings(this); settings = new Settings(this);
// Get the BSkyBlock database // Get the BSkyBlock database

View File

@ -0,0 +1,89 @@
/**
*
*/
package bentobox.addon.level;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import bentobox.addon.level.calculators.PlayerLevel;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, LevelPresenter.class})
public class LevelPresenterTest {
private BentoBox plugin;
private Level addon;
private IslandsManager im;
private PlayerLevel pl;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
plugin = mock(BentoBox.class);
addon = mock(Level.class);
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("world");
im = mock(IslandsManager.class);
when(plugin.getIslands()).thenReturn(im);
// Has island
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
// In team
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
// team leader
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(UUID.randomUUID());
pl = mock(PlayerLevel.class);
PowerMockito.whenNew(PlayerLevel.class).withAnyArguments().thenReturn(pl);
}
/**
* Test method for {@link bentobox.addon.level.LevelPresenter#LevelPresenter(bentobox.addon.level.Level, world.bentobox.bentobox.BentoBox)}.
*/
@Test
public void testLevelPresenter() {
assertNotNull(new LevelPresenter(addon, plugin));
}
/**
* Test method for {@link bentobox.addon.level.LevelPresenter#calculateIslandLevel(org.bukkit.World, world.bentobox.bentobox.api.user.User, java.util.UUID)}.
*/
@Test
public void testCalculateIslandLevel() {
LevelPresenter lp = new LevelPresenter(addon, plugin);
World world = mock(World.class);
User sender = mock(User.class);
UUID targetPlayer = UUID.randomUUID();
lp.calculateIslandLevel(world, sender, targetPlayer);
Mockito.verify(sender).sendMessage("island.level.calculating");
// Verify PlayerLevel was called
Mockito.verify(pl);
}
}