use of org.spongepowered.api.service.permission.Subject in project Nucleus by NucleusPowered.
the class ListGroupTests method createSubject.
private static Subject createSubject(String name, Subject... parents) {
Subject subject = Mockito.mock(Subject.class);
List<Subject> ls = Arrays.asList(parents);
Mockito.when(subject.getIdentifier()).thenReturn(name);
Mockito.when(subject.getOption(Mockito.anySetOf(Context.class), Mockito.eq("nucleus.list.weight"))).then(x -> ls.stream().map(y -> y.getOption("nucleus.list.weight")).filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
Mockito.when(subject.getOption(Mockito.eq("nucleus.list.weight"))).then(x -> ls.stream().map(y -> y.getOption("nucleus.list.weight")).filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
List<SubjectReference> lsr = getSubjectReferences(Arrays.asList(parents));
Mockito.when(subject.getParents()).thenReturn(lsr);
Mockito.when(subject.getParents(Mockito.anySetOf(Context.class))).thenReturn(lsr);
return subject;
}
use of org.spongepowered.api.service.permission.Subject in project Nucleus by NucleusPowered.
the class ListGroupTests method testWeightsAreBeingAppliedCorrectlyWithAliases.
@Test
@SuppressWarnings("all")
public void testWeightsAreBeingAppliedCorrectlyWithAliases() {
// Create two groups.
Subject admin = createSubjectWithWeight("admin", 1);
Subject ace = createSubjectWithWeight("ace", 0);
// The player is in both groups. Also, order is important.
List<Subject> parents = Lists.newArrayList(admin, ace);
Player player = Mockito.mock(Player.class);
List<SubjectReference> lsr = getSubjectReferences(parents);
Mockito.when(player.getParents()).thenReturn(lsr);
Mockito.when(player.getParents(Mockito.anySet())).thenReturn(lsr);
// Create our map.
Map<Player, List<String>> map = Maps.newHashMap();
map.put(player, Lists.newArrayList("admin", "ace"));
// No aliases.
Map<String, String> aliases = Maps.newHashMap();
aliases.put("admin", "Admin");
aliases.put("ace", "Ace");
// Now, let's run it through our method.
Map<String, List<Player>> result = ListPlayerCommand.linkPlayersToGroups(parents, aliases, map);
Assert.assertEquals("There should only be one entry", 1, result.size());
List<Player> players = result.get("Admin");
Assert.assertNotNull("Players is null", players);
Assert.assertEquals("There should only be one player!", 1, players.size());
Assert.assertTrue("map is not empty", map.isEmpty());
}
use of org.spongepowered.api.service.permission.Subject in project Nucleus by NucleusPowered.
the class ListGroupTests method testTwoGroupsWithWeights.
@Test
public void testTwoGroupsWithWeights() {
Subject admin = createSubjectWithWeight("admin", 1);
Subject ace = createSubjectWithWeight("ace", 0);
Assert.assertEquals(-1, ListPlayerCommand.groupComparison(ListPlayerCommand.weightingFunction, admin, ace));
}
Aggregations