-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
125 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
MarriageMaster/test/src/at/pcgamingfreaks/MarriageMaster/PermissionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2020 GeorgH93 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package at.pcgamingfreaks.MarriageMaster; | ||
|
||
import at.pcgamingfreaks.yaml.YAML; | ||
import at.pcgamingfreaks.yaml.YamlInvalidContentException; | ||
import at.pcgamingfreaks.yaml.YamlKeyNotFoundException; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.Field; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class PermissionsTest | ||
{ | ||
private static Collection<String> permissions; | ||
|
||
@BeforeAll | ||
public static void setup() throws IllegalAccessException | ||
{ // Collect all permissions defined in the Permissions class | ||
permissions = new HashSet<>(); | ||
for(Field declaredField : Permissions.class.getDeclaredFields()) | ||
{ | ||
if(declaredField.getName().equals("BASE") || declaredField.getName().equals("BYPASS")) continue; | ||
permissions.add((String) declaredField.get(null)); | ||
} | ||
} | ||
|
||
private int countKeysStartingWith(Collection<String> keys, String startsWith) | ||
{ | ||
int count = 0; | ||
for(String key : keys) | ||
{ | ||
if(key.startsWith(startsWith)) count++; | ||
} | ||
return count; | ||
} | ||
|
||
@Test | ||
public void testPermissionsInPluginYaml() throws IOException, YamlInvalidContentException, YamlKeyNotFoundException | ||
{ | ||
YAML pluginYaml = new YAML(new File("resources/plugin.yml")); | ||
YAML permissionsYaml = pluginYaml.getSection("permissions"); | ||
// Check if all permissions are defined in the plugin.yml | ||
for(String permission : permissions) | ||
{ | ||
assertTrue(permissionsYaml.isSet(permission + ".description"), "The plugin.yml should contain the permission " + permission); | ||
} | ||
// Check if all the permissions defined in the plugin.yml are also defined in the Permissions class | ||
Collection<String> keys = permissionsYaml.getKeys(true); | ||
for(String key : keys) | ||
{ | ||
if(!key.endsWith("description")) continue; | ||
String perm = key.substring(0, key.length() - 12); | ||
if(perm.contains(".size.")) continue; // Ignore size permissions | ||
if(countKeysStartingWith(keys, perm + ".children") > 1) continue; // Skip all the permissions that are just for permission grouping | ||
assertTrue(permissions.contains(perm), "The plugin.yml should not contain the permission " + perm); | ||
} | ||
} | ||
} |