Skip to content

Commit

Permalink
Reorganize test directory layout (#7269)
Browse files Browse the repository at this point in the history
* Reorganize test directory layout

* Clean up imports

* protected not required

* this was used somewhere else
  • Loading branch information
Warriorrrr authored Feb 19, 2024
1 parent 681259e commit 95e563c
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.bukkit.Registry;
import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
Expand Down Expand Up @@ -52,8 +51,7 @@ public boolean contains(@NotNull String element) {
return matched != null && this.contains(matched);
}

@VisibleForTesting
public Collection<T> tagged() {
protected Collection<T> tagged() {
return this.tagged;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.palmergames.bukkit.towny.object;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void addCommand(@NotNull String command) {
current.endOfWord = true;
}

@VisibleForTesting
@ApiStatus.Internal
public static String normalizeCommand(String command) {
// Replace slash and/or space from the start of a command
command = REMOVE_LEADING_SPACE.matcher(command).replaceAll("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -397,8 +396,7 @@ public boolean hasResidentWithRank(Resident resident, String rank) {
*
* @param resident Resident that gets added to the town.
*/
@VisibleForTesting
public void addResident(Resident resident) {
void addResident(Resident resident) {
residents.add(resident);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.jetbrains.annotations.VisibleForTesting;

/**
* @author ElgarL
*
Expand Down Expand Up @@ -401,8 +399,7 @@ private static String filterCommas(String input) {
* @param name String to check.
* @return true if this is a banned name.
*/
@VisibleForTesting
public static boolean isBannedName(String name) {
static boolean isBannedName(String name) {
return bannedNames.contains(name.toLowerCase(Locale.ROOT));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.config;

import be.seeseemelk.mockbukkit.MockBukkit;
import com.palmergames.bukkit.config.ConfigNodes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.config;

import be.seeseemelk.mockbukkit.MockBukkit;
import com.palmergames.bukkit.config.CommentedConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.config;

import be.seeseemelk.mockbukkit.MockBukkit;
import com.palmergames.bukkit.towny.TownySettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.object;

import com.palmergames.bukkit.towny.object.CommandList;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.object;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;

import be.seeseemelk.mockbukkit.MockBukkit;

Expand Down Expand Up @@ -54,12 +51,12 @@ void reset() {

@Test
void testSuccessAddResidentNoRestrictionsWithoutCapital() {
assertEquals(town.isAllowedThisAmountOfResidents(10, false), true);
assertTrue(town.isAllowedThisAmountOfResidents(10, false));
}

@Test
void testSuccessAddResidentNoRestrictionsWithCapital() {
assertEquals(town.isAllowedThisAmountOfResidents(10, true), true);
assertTrue(town.isAllowedThisAmountOfResidents(10, true));
}

/*
Expand All @@ -70,14 +67,14 @@ void testSuccessAddResidentNoRestrictionsWithCapital() {
void testSuccessAllowTownPopulationWithRestrictionsWithoutCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 5);
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_CAPITAL_OVERRIDE.getRoot(), 10);
assertEquals(town.isAllowedThisAmountOfResidents(5, false), true);
assertTrue(town.isAllowedThisAmountOfResidents(5, false));
}

@Test
void testFailAllowTownPopulationWithRestrictionsWithoutCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 5);
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_CAPITAL_OVERRIDE.getRoot(), 10);
assertEquals(town.isAllowedThisAmountOfResidents(10, false), false);
assertFalse(town.isAllowedThisAmountOfResidents(10, false));
}

/*
Expand All @@ -88,14 +85,14 @@ void testFailAllowTownPopulationWithRestrictionsWithoutCapital() {
void testSuccessAllowTownPopulationWithRestrictionsWithCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 5);
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_CAPITAL_OVERRIDE.getRoot(), 10);
assertEquals(town.isAllowedThisAmountOfResidents(10, true), true);
assertTrue(town.isAllowedThisAmountOfResidents(10, true));
}

@Test
void testFailureAllowTownPopulationWithRestrictionsWithCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 5);
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_CAPITAL_OVERRIDE.getRoot(), 10);
assertEquals(town.isAllowedThisAmountOfResidents(11, true), false);
assertFalse(town.isAllowedThisAmountOfResidents(11, true));
}

/*
Expand All @@ -106,21 +103,21 @@ void testFailureAllowTownPopulationWithRestrictionsWithCapital() {
void testSuccessAllowNationlessTownPopulationWithFeatureDisabled() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 10);
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_MAX_NUMBER_RESIDENTS_WITHOUT_NATION.getRoot(), 0);
assertEquals(town.isAllowedThisAmountOfResidents(5, false), true);
assertTrue(town.isAllowedThisAmountOfResidents(5, false));
}

@Test
void testSuccessAllowNationlessTownPopulation() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 10);
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_MAX_NUMBER_RESIDENTS_WITHOUT_NATION.getRoot(), 5);
assertEquals(town.isAllowedThisAmountOfResidents(5, false), true);
assertTrue(town.isAllowedThisAmountOfResidents(5, false));
}

@Test
void testFailureAllowNationlessTownPopulation() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_MAX_RESIDENTS_PER_TOWN.getRoot(), 10);
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_MAX_NUMBER_RESIDENTS_WITHOUT_NATION.getRoot(), 5);
assertEquals(town.isAllowedThisAmountOfResidents(6, false), false);
assertFalse(town.isAllowedThisAmountOfResidents(6, false));
}

/*
Expand All @@ -130,19 +127,19 @@ void testFailureAllowNationlessTownPopulation() {
@Test
void testSuccessTownMakingNationWithFeatureDisabled() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_CREATE_NATION.getRoot(), 0);
assertEquals(town.hasEnoughResidentsToBeANationCapital(), true);
assertTrue(town.hasEnoughResidentsToBeANationCapital());
}

@Test
void testSucceedTownPopAllowsBeingCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_CREATE_NATION.getRoot(), 5);
assertEquals(town.hasEnoughResidentsToBeANationCapital(), true);
assertTrue(town.hasEnoughResidentsToBeANationCapital());
}

@Test
void testFailTownPopAllowsBeingCapital() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_CREATE_NATION.getRoot(), 6);
assertEquals(town.hasEnoughResidentsToBeANationCapital(), false);
assertFalse(town.hasEnoughResidentsToBeANationCapital());
}

/*
Expand All @@ -152,19 +149,19 @@ void testFailTownPopAllowsBeingCapital() {
@Test
void testSuccessTownJoiningNationWithFeatureDisabled() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_JOIN_NATION.getRoot(), 0);
assertEquals(town.hasEnoughResidentsToBeANationCapital(), true);
assertTrue(town.hasEnoughResidentsToBeANationCapital());
}

@Test
void testSucceedTownPopAllowsJoiningNation() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_JOIN_NATION.getRoot(), 5);
assertEquals(town.hasEnoughResidentsToJoinANation(), true);
assertTrue(town.hasEnoughResidentsToJoinANation());
}

@Test
void testFailTownPopAllowsJoiningNation() {
TownySettings.getConfig().set(ConfigNodes.GTOWN_SETTINGS_REQUIRED_NUMBER_RESIDENTS_JOIN_NATION.getRoot(), 6);
assertEquals(town.hasEnoughResidentsToJoinANation(), false);
assertFalse(town.hasEnoughResidentsToJoinANation());
}

/*
Expand All @@ -175,21 +172,21 @@ void testFailTownPopAllowsJoiningNation() {
void testSuccessNationAddingResidentsWithFeatureDisabled() {
TownySettings.getConfig().set(ConfigNodes.GNATION_SETTINGS_MAX_RESIDENTS_PER_NATION.getRoot(), 0);
nation.addTown(town);
assertEquals(nation.canAddResidents(1), true);
assertTrue(nation.canAddResidents(1));
}

@Test
void testSuccessNationAddingResidents() {
TownySettings.getConfig().set(ConfigNodes.GNATION_SETTINGS_MAX_RESIDENTS_PER_NATION.getRoot(), 7);
nation.addTown(town);
assertEquals(nation.canAddResidents(1), true);
assertTrue(nation.canAddResidents(1));
}

@Test
void testFailureNationAddingResidents() {
TownySettings.getConfig().set(ConfigNodes.GNATION_SETTINGS_MAX_RESIDENTS_PER_NATION.getRoot(), 5);
nation.addTown(town);
assertEquals(nation.canAddResidents(1), false);
assertFalse(nation.canAddResidents(1));
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.palmergames.bukkit.towny.test;
package com.palmergames.bukkit.towny.object;

import be.seeseemelk.mockbukkit.MockBukkit;
import com.palmergames.bukkit.towny.TownySettings;
Expand Down

This file was deleted.

Loading

0 comments on commit 95e563c

Please sign in to comment.