mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-28 06:26:00 +01:00
Fixed most of the already written tests with Mocking
**Pit** Line coverage: 613/4256 (14%) Mutation coverage 181/1975 (9%) Next step is to mock scheduler to be able to test database with unit tests.
This commit is contained in:
parent
de28ed4612
commit
39ed2de9dd
@ -55,7 +55,7 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- -->
|
||||
<!-- <dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock</artifactId>
|
||||
<version>1.6.6</version>
|
||||
@ -98,7 +98,7 @@
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -183,8 +183,10 @@ public class UserData {
|
||||
* @param loc
|
||||
*/
|
||||
public void addLocation(Location loc) {
|
||||
locations.add(loc);
|
||||
location = loc;
|
||||
if (loc != null) {
|
||||
locations.add(loc);
|
||||
location = loc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,8 +194,9 @@ public class UserData {
|
||||
* @param addLocs
|
||||
*/
|
||||
public void addLocations(Collection<Location> addLocs) {
|
||||
locations.addAll(addLocs);
|
||||
if (!locations.isEmpty()) {
|
||||
if (!addLocs.isEmpty()) {
|
||||
List<Location> locs = addLocs.stream().filter(l -> l != null).collect(Collectors.toList());
|
||||
locations.addAll(locs);
|
||||
location = locations.get(locations.size() - 1);
|
||||
}
|
||||
}
|
||||
|
@ -6,22 +6,48 @@
|
||||
package test.java.main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Before;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class PhraseTest {
|
||||
|
||||
private Plan plan;
|
||||
|
||||
public PhraseTest() {
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
public void testToString() {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Phrase instance = Phrase.REPLACE0;
|
||||
String expResult = "REPLACE0";
|
||||
instance.setText(expResult);
|
||||
@ -29,15 +55,15 @@ public class PhraseTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testParse_0args() {
|
||||
Phrase instance = Phrase.REPLACE0;
|
||||
String expResult = "REPLACE0";
|
||||
Phrase instance = Phrase.DEM_UNKNOWN;
|
||||
String expResult = "Not Known";
|
||||
String result = instance.parse();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testParse_StringArr() {
|
||||
Phrase instance = Phrase.REPLACE0;
|
||||
String expResult = "Test";
|
||||
@ -45,7 +71,7 @@ public class PhraseTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testColor() {
|
||||
Phrase instance = Phrase.COLOR_MAIN;
|
||||
ChatColor expResult = ChatColor.RED;
|
||||
@ -54,7 +80,7 @@ public class PhraseTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testSetText() {
|
||||
Phrase instance = Phrase.REPLACE0;
|
||||
String expResult = "Test";
|
||||
|
@ -6,22 +6,45 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data;
|
||||
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.Gender;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class DemographicsDataTest {
|
||||
|
||||
public DemographicsDataTest() {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAge() {
|
||||
DemographicsData instance = new DemographicsData();
|
||||
@ -30,7 +53,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetAge2() {
|
||||
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
|
||||
@ -39,7 +61,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetGender() {
|
||||
DemographicsData instance = new DemographicsData();
|
||||
@ -48,7 +69,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetGender2() {
|
||||
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
|
||||
@ -57,7 +77,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetGeoLocation() {
|
||||
DemographicsData instance = new DemographicsData();
|
||||
@ -66,7 +85,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetGeoLocation2() {
|
||||
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
|
||||
@ -75,7 +93,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetAge() {
|
||||
int age = 10;
|
||||
@ -85,7 +102,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(age, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetGender() {
|
||||
Gender gender = Gender.MALE;
|
||||
@ -95,7 +111,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(gender, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetGeoLocation() {
|
||||
String geoLocation = "None";
|
||||
@ -105,7 +120,6 @@ public class DemographicsDataTest {
|
||||
assertEquals(geoLocation, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testToString() {
|
||||
DemographicsData instance = new DemographicsData();
|
||||
|
@ -11,34 +11,55 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class UserDataTest {
|
||||
|
||||
private UserData test;
|
||||
|
||||
public UserDataTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
DemographicsData demData = new DemographicsData();
|
||||
test = new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, demData, "Testname", true);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddIpAddress() throws UnknownHostException {
|
||||
InetAddress ip = InetAddress.getByName("247.183.163.155");
|
||||
@ -53,7 +74,6 @@ public class UserDataTest {
|
||||
assertTrue("Added multiples", test.getIps().size() == 2);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddIpAddresses() throws UnknownHostException {
|
||||
List<InetAddress> ips = new ArrayList<>();
|
||||
@ -70,7 +90,6 @@ public class UserDataTest {
|
||||
assertTrue("Added multiples", test.getIps().size() == 2);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddIpAddressesEmpty() {
|
||||
List<InetAddress> ips = new ArrayList<>();
|
||||
@ -78,17 +97,36 @@ public class UserDataTest {
|
||||
assertTrue("Added something", test.getIps().isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddLocation() {
|
||||
World mockWorld = MockUtils.mockWorld();
|
||||
Location loc = new Location(mockWorld, 0, 0, 0);
|
||||
test.addLocation(loc);
|
||||
assertTrue("Didn't add location", !test.getLocations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNullLocation() {
|
||||
test.addLocation(null);
|
||||
assertTrue("Added location", test.getLocations().isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddLocations() {
|
||||
World mockWorld = MockUtils.mockWorld();
|
||||
Location loc = new Location(mockWorld, 0, 0, 0);
|
||||
Location loc2 = new Location(mockWorld, 1, 0, 1);
|
||||
List<Location> locs = new ArrayList<>();
|
||||
locs.add(loc);
|
||||
locs.add(loc2);
|
||||
locs.add(null);
|
||||
test.addLocations(locs);
|
||||
List<Location> locations = test.getLocations();
|
||||
assertTrue("Didn't add locations", !locations.isEmpty());
|
||||
assertTrue("Didn't add 2 locations", locations.size() == 2);
|
||||
assertTrue("Added null", !locations.contains(null));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddNickname() {
|
||||
String one = "Test1";
|
||||
@ -106,7 +144,6 @@ public class UserDataTest {
|
||||
assertTrue("Added multiples", test.getNicknames().size() == 2);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddNicknames() {
|
||||
String one = "Test1";
|
||||
@ -123,7 +160,6 @@ public class UserDataTest {
|
||||
assertTrue("Added multiples", test.getNicknames().size() == 2);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddNicknamesEmpty() {
|
||||
List<String> o = new ArrayList<>();
|
||||
@ -131,14 +167,12 @@ public class UserDataTest {
|
||||
assertTrue("Added something", test.getNicknames().isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetGMTime() {
|
||||
test.setGMTime(GameMode.SURVIVAL, 1L);
|
||||
assertTrue("" + test.getGmTimes().get(GameMode.SURVIVAL), test.getGmTimes().get(GameMode.SURVIVAL) == 1L);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetGMTimeWhenGMTimesNull() {
|
||||
test.setGmTimes(null);
|
||||
@ -146,14 +180,12 @@ public class UserDataTest {
|
||||
assertTrue("" + test.getGmTimes().get(GameMode.SURVIVAL), test.getGmTimes().get(GameMode.SURVIVAL) == 1L);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetGMTimeNull() {
|
||||
test.setGMTime(null, 0L);
|
||||
assertTrue("Added null", !test.getGmTimes().containsKey(null));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetAllGMTimes() {
|
||||
HashMap<GameMode, Long> gmTimes = new HashMap<>();
|
||||
@ -168,7 +200,6 @@ public class UserDataTest {
|
||||
assertTrue("Not equal 3", times.get(GameMode.SPECTATOR) == 4L);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddSession() {
|
||||
SessionData correct = new SessionData(0, 1);
|
||||
@ -176,7 +207,6 @@ public class UserDataTest {
|
||||
assertTrue("Didn't add correct one", test.getSessions().contains(correct));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddSessionIncorrect() {
|
||||
SessionData incorrect = new SessionData(0);
|
||||
@ -184,7 +214,6 @@ public class UserDataTest {
|
||||
assertTrue("Added incorrect one", !test.getSessions().contains(incorrect));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddSessionNull() {
|
||||
SessionData incorrect = null;
|
||||
@ -192,7 +221,6 @@ public class UserDataTest {
|
||||
assertTrue("Added null", !test.getSessions().contains(incorrect));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddSessions() {
|
||||
SessionData correct = new SessionData(0, 1);
|
||||
@ -207,7 +235,6 @@ public class UserDataTest {
|
||||
assertTrue("Added null", !test.getSessions().contains(incorrect));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAddSessionsEmpty() {
|
||||
List<SessionData> o = new ArrayList<>();
|
||||
@ -215,7 +242,6 @@ public class UserDataTest {
|
||||
assertTrue("Added something", test.getSessions().isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetCurrentSession() {
|
||||
SessionData s = new SessionData(0);
|
||||
@ -223,7 +249,6 @@ public class UserDataTest {
|
||||
assertEquals(test.getCurrentSession(), s);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUpdateBanned() {
|
||||
test.updateBanned(true);
|
||||
@ -232,7 +257,6 @@ public class UserDataTest {
|
||||
assertTrue("True", !test.isBanned());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testIsAccessed() {
|
||||
test.access();
|
||||
@ -244,14 +268,12 @@ public class UserDataTest {
|
||||
assertTrue("Accessed, even though not accessing", !test.isAccessed());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testAccess() {
|
||||
test.access();
|
||||
assertTrue("Not accessed, even though accessing", test.isAccessed());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testStopAccessing() {
|
||||
test.access();
|
||||
@ -259,34 +281,29 @@ public class UserDataTest {
|
||||
assertTrue("Accessed, even though not accessing", !test.isAccessed());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertTrue("Not Equals!", test.equals(new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, null, "Testname", true)));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testEqualsNot() {
|
||||
UserData notEqual = new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, null, "WRONG", true);
|
||||
assertTrue("Equals!", !notEqual.equals(test));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testEqualsNot2() {
|
||||
Object o = "NOT";
|
||||
assertTrue("Equals!", !test.equals(o));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testCopyConstructor() {
|
||||
UserData copy = new UserData(test);
|
||||
assertTrue("Not copied properly", test.equals(copy));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetUUID() {
|
||||
assertEquals(test.getUuid(), UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"));
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.database;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import test.java.utils.TestInit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class DatabaseTest {
|
||||
|
||||
private Plan plan;
|
||||
private int rows;
|
||||
|
||||
public DatabaseTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
PowerMock.mockStatic(Bukkit.class);
|
||||
PowerMock.replay(Bukkit.class);
|
||||
// EasyMock.expect(Bukkit.getScheduler()).andReturn();
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
rows = 0;
|
||||
if (f.exists()) {
|
||||
rows = Files.readLines(f, Charset.defaultCharset()).size();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
int rowsAgain = 0;
|
||||
if (f.exists()) {
|
||||
rowsAgain = Files.readLines(f, Charset.defaultCharset()).size();
|
||||
}
|
||||
assertTrue("Errors were caught.", rows == rowsAgain);
|
||||
}
|
||||
|
||||
@Ignore("Mock scheduler") @Test
|
||||
public void testInit() {
|
||||
Database db = new SQLiteDB(plan, "debug.db");
|
||||
assertTrue("Database failed to init.", db.init());
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ public class PlayerActivityGraphCreatorTest {
|
||||
public PlayerActivityGraphCreatorTest() {
|
||||
}
|
||||
|
||||
@Ignore("Takes too long") @Test
|
||||
@Test
|
||||
public void testGenerateDataArray() {
|
||||
List<SessionData> sessionData = createRandomSessionDataList();
|
||||
long scale = 2592000L * 1000L;
|
||||
|
@ -9,26 +9,80 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class AnalysisUtilsTest {
|
||||
|
||||
public AnalysisUtilsTest() {
|
||||
}
|
||||
|
||||
@Ignore("Mock Settings")@Test
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsActive() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 4;
|
||||
boolean expResult = true;
|
||||
boolean result = AnalysisUtils.isActive(lastPlayed, playTime, loginTimes);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotActive2() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long playTime = 0L;
|
||||
int loginTimes = 4;
|
||||
boolean expResult = false;
|
||||
boolean result = AnalysisUtils.isActive(lastPlayed, playTime, loginTimes);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotActive3() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 0;
|
||||
boolean expResult = false;
|
||||
boolean result = AnalysisUtils.isActive(lastPlayed, playTime, loginTimes);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotActive() {
|
||||
long lastPlayed = 0L;
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 4;
|
||||
boolean expResult = false;
|
||||
boolean result = AnalysisUtils.isActive(lastPlayed, playTime, loginTimes);
|
||||
assertEquals(expResult, result);
|
||||
|
@ -10,7 +10,8 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Ignore;
|
||||
import org.bukkit.World;
|
||||
import test.java.utils.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -88,14 +89,13 @@ public class FormatUtilsTest {
|
||||
assertArrayEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Ignore @Test
|
||||
@Test
|
||||
public void testFormatLocation() {
|
||||
Location loc = null;
|
||||
String expResult = "";
|
||||
World mockWorld = MockUtils.mockWorld();
|
||||
Location loc = new Location(mockWorld, 0, 0, 0);
|
||||
String expResult = "x 0 z 0 in World";
|
||||
String result = FormatUtils.formatLocation(loc);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5,30 +5,52 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class HtmlUtilsTest {
|
||||
|
||||
public HtmlUtilsTest() {
|
||||
}
|
||||
|
||||
@Ignore("Mock JavaPlugin") @Test
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHtmlStringFromResource() throws Exception {
|
||||
System.out.println("getHtmlStringFromResource");
|
||||
String fileName = "";
|
||||
String expResult = "";
|
||||
String fileName = "player.html";
|
||||
String result = HtmlUtils.getHtmlStringFromResource(fileName);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
assertTrue("Result null", result != null);
|
||||
assertTrue("Result empty", !result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -50,17 +72,14 @@ public class HtmlUtilsTest {
|
||||
assertEquals(result, exp);
|
||||
}
|
||||
|
||||
@Ignore("Mock JavaPlugin") @Test
|
||||
public void testGetServerAnalysisUrl() {
|
||||
System.out.println("getServerAnalysisUrl");
|
||||
String expResult = "";
|
||||
@Ignore("Mock Server.getIp") @Test
|
||||
public void testGetServerAnalysisUrl() throws FileNotFoundException {
|
||||
String result = HtmlUtils.getServerAnalysisUrl();
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
String exp = "";
|
||||
assertEquals(result, exp);
|
||||
}
|
||||
|
||||
@Ignore("Mock JavaPlugin") @Test
|
||||
@Ignore("Mock Server.getIp") @Test
|
||||
public void testGetInspectUrl() {
|
||||
String playerName = "";
|
||||
String expResult = "";
|
||||
|
@ -7,23 +7,47 @@ package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.Set;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class MiscUtilsTest {
|
||||
|
||||
public MiscUtilsTest() {
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckVersion() {
|
||||
String versionG = "2.10.9";
|
||||
String result = MiscUtils.checkVersion("2.0.0", versionG);
|
||||
@ -31,21 +55,21 @@ public class MiscUtilsTest {
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Ignore @Test
|
||||
@Test
|
||||
public void testCheckVersion2() {
|
||||
String result = MiscUtils.checkVersion("3.0.0", "2.10.9");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Ignore @Test
|
||||
@Test
|
||||
public void testCheckVersion3() {
|
||||
String result = MiscUtils.checkVersion("2.11.0", "2.10.9");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testCheckVersion4() {
|
||||
String result = MiscUtils.checkVersion("2.11.0", "2.11.0");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
|
17
Plan/src/test/java/utils/MockUtils.java
Normal file
17
Plan/src/test/java/utils/MockUtils.java
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
package test.java.utils;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MockUtils {
|
||||
public static World mockWorld() {
|
||||
World mockWorld = Mockito.mock(World.class);
|
||||
Mockito.doReturn("World").when(mockWorld).toString();
|
||||
return mockWorld;
|
||||
}
|
||||
}
|
62
Plan/src/test/java/utils/TestInit.java
Normal file
62
Plan/src/test/java/utils/TestInit.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.mockito.Mockito;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class TestInit {
|
||||
|
||||
private Plan planMock;
|
||||
|
||||
public TestInit() {
|
||||
}
|
||||
|
||||
public boolean setUp() {
|
||||
try {
|
||||
planMock = Mockito.mock(Plan.class);
|
||||
File configfile = new File(getClass().getResource("/config.yml").getPath());
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
configuration.load(configfile.getAbsolutePath());
|
||||
when(planMock.getConfig()).thenReturn(configuration);
|
||||
// if (testFolder.exists()) {
|
||||
// Files.deleteIfExists(testFolder.toPath());
|
||||
// }
|
||||
// testFolder.mkdir();
|
||||
// when(planMock.getDataFolder()).thenReturn(new File("temporaryTestFolder"));
|
||||
File analysis = new File(getClass().getResource("/analysis.html").getPath());
|
||||
when(planMock.getResource("analysis.html")).thenReturn(new FileInputStream(analysis));
|
||||
File player = new File(getClass().getResource("/player.html").getPath());
|
||||
when(planMock.getResource("player.html")).thenReturn(new FileInputStream(player));
|
||||
|
||||
// Server mockServer = Mockito.mock(Server.class);
|
||||
// when(mockServer.getIp()).thenReturn("0.0.0.0");
|
||||
// Mockito.doReturn("0.0.0.0").when(mockServer).getIp();
|
||||
// when(planMock.getServer()).thenReturn(mockServer);
|
||||
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
StackTraceElement[] stackTrace = ex.getStackTrace();
|
||||
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||
System.out.println(stackTraceElement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Plan getPlanMock() {
|
||||
return planMock;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user