mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-07 04:18:26 +02:00
Moved Sponge tests to JUnit 5
This commit is contained in:
parent
c3f9d77698
commit
cc8d7b8e9f
@ -22,48 +22,41 @@ import com.djrapitops.plan.system.settings.ConfigSettingKeyTest;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import rules.ComponentMocker;
|
||||
import rules.SpongeComponentMocker;
|
||||
import utilities.RandomData;
|
||||
import utilities.mocks.SpongeMockComponent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Test for Sponge PlanSystem.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
@RunWith(JUnitPlatform.class)
|
||||
public class SpongeSystemTest {
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ComponentMocker component = new SpongeComponentMocker(temporaryFolder);
|
||||
|
||||
private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||
|
||||
private PlanSystem system;
|
||||
|
||||
@Before
|
||||
public void prepareSpongeSystem() {
|
||||
system = component.getPlanSystem();
|
||||
@BeforeEach
|
||||
void prepareSpongeSystem(@TempDir Path temp) throws Exception {
|
||||
system = new SpongeMockComponent(temp).getPlanSystem();
|
||||
system.getConfigSystem().getConfig()
|
||||
.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spongeSystemEnables() throws EnableException {
|
||||
void spongeSystemEnables() throws EnableException {
|
||||
try {
|
||||
system.enable();
|
||||
assertTrue(system.isEnabled());
|
||||
@ -73,7 +66,7 @@ public class SpongeSystemTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spongeSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException {
|
||||
void spongeSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException {
|
||||
try {
|
||||
system.enable();
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
|
@ -86,12 +86,12 @@ public class PlanSpongeMocker extends Mocker {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanSpongeMocker withDataFolder(File tempFolder) {
|
||||
PlanSpongeMocker withDataFolder(File tempFolder) {
|
||||
when(planMock.getDataFolder()).thenReturn(tempFolder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanSpongeMocker withGame() {
|
||||
PlanSpongeMocker withGame() {
|
||||
Game game = Mockito.mock(Game.class);
|
||||
|
||||
Platform platform = mockPlatform();
|
||||
@ -130,12 +130,12 @@ public class PlanSpongeMocker extends Mocker {
|
||||
return server;
|
||||
}
|
||||
|
||||
public PlanSpongeMocker withResourceFetchingFromJar() throws Exception {
|
||||
PlanSpongeMocker withResourceFetchingFromJar() throws Exception {
|
||||
withPluginFiles();
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanSponge getPlanMock() {
|
||||
PlanSponge getPlanMock() {
|
||||
return planMock;
|
||||
}
|
||||
}
|
||||
|
@ -14,44 +14,46 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package rules;
|
||||
package utilities.mocks;
|
||||
|
||||
import com.djrapitops.plan.DaggerPlanSpongeComponent;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.PlanSponge;
|
||||
import com.djrapitops.plan.PlanSpongeComponent;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import org.junit.rules.ExternalResource;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import utilities.mocks.PlanSpongeMocker;
|
||||
|
||||
public class SpongeComponentMocker extends ExternalResource implements ComponentMocker {
|
||||
import java.nio.file.Path;
|
||||
|
||||
private final TemporaryFolder testFolder;
|
||||
/**
|
||||
* Test utility for creating a dagger PlanComponent using a mocked PlanSponge.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SpongeMockComponent {
|
||||
|
||||
private final Path tempDir;
|
||||
|
||||
private PlanSponge planMock;
|
||||
private PlanSpongeComponent component;
|
||||
|
||||
public SpongeComponentMocker(TemporaryFolder testFolder) {
|
||||
this.testFolder = testFolder;
|
||||
public SpongeMockComponent(Path tempDir) {
|
||||
this.tempDir = tempDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void before() throws Throwable {
|
||||
PlanSpongeMocker mocker = PlanSpongeMocker.setUp()
|
||||
.withDataFolder(testFolder.newFolder())
|
||||
.withResourceFetchingFromJar()
|
||||
.withGame();
|
||||
planMock = mocker.getPlanMock();
|
||||
component = DaggerPlanSpongeComponent.builder().plan(planMock).build();
|
||||
}
|
||||
|
||||
public PlanPlugin getPlanMock() {
|
||||
public PlanSponge getPlanMock() throws Exception {
|
||||
if (planMock == null) {
|
||||
planMock = PlanSpongeMocker.setUp()
|
||||
.withDataFolder(tempDir.toFile())
|
||||
.withResourceFetchingFromJar()
|
||||
.withGame()
|
||||
.getPlanMock();
|
||||
}
|
||||
return planMock;
|
||||
}
|
||||
|
||||
public PlanSystem getPlanSystem() {
|
||||
public PlanSystem getPlanSystem() throws Exception {
|
||||
if (component == null) {
|
||||
component = DaggerPlanSpongeComponent.builder().plan(getPlanMock()).build();
|
||||
}
|
||||
return component.system();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user