コード例 #1
0
  @Test
  public void shouldSavePlayerData() {
    // given
    Player player = mock(Player.class);
    UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
    given(player.getUniqueId()).willReturn(uuid);
    given(permissionsManager.getPrimaryGroup(player)).willReturn("primary-grp");
    given(player.isOp()).willReturn(true);
    given(player.getWalkSpeed()).willReturn(1.2f);
    given(player.getFlySpeed()).willReturn(0.8f);
    given(player.getAllowFlight()).willReturn(true);

    World world = mock(World.class);
    given(world.getName()).willReturn("player-world");
    Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
    given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(location);

    // when
    limboPlayerStorage.saveData(player);

    // then
    File playerFile =
        new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json"));
    assertThat(playerFile.exists(), equalTo(true));
    // TODO ljacqu 20160711: Check contents of file
  }
コード例 #2
0
  @Test
  public void shouldHandleUnknownBase() {
    // given
    List<String> parts = asList("bogus", "label1", "arg1");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.MISSING_BASE_COMMAND));
    assertThat(result.getCommandDescription(), nullValue());
  }
コード例 #3
0
  /** In contrast to the previous test, we test a command request with a very apart label. */
  @Test
  public void shouldSuggestMostSimilarCommand() {
    // given
    List<String> parts = asList("authme", "asdfawetawty4asdca");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getCommandDescription(), not(nullValue()));
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.UNKNOWN_LABEL));
    assertThat(result.getDifference() > 0.75, equalTo(true));
    assertThat(result.getLabels(), equalTo(parts));
    assertThat(result.getArguments(), empty());
  }
コード例 #4
0
  @Test
  public void shouldReturnChildlessBaseCommandWithArgCountError() {
    // given
    List<String> parts = asList("unregistER", "player1", "wrongArg");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
    assertThat(
        result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
    assertThat(result.getDifference(), equalTo(0.0));
    assertThat(result.getArguments(), contains("player1", "wrongArg"));
    assertThat(result.getLabels(), contains("unregistER"));
  }
コード例 #5
0
  @Test
  public void shouldMapToBaseWithProperArguments() {
    // given
    List<String> parts = asList("Unreg", "player1");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.SUCCESS));
    assertThat(
        result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
    assertThat(result.getDifference(), equalTo(0.0));
    assertThat(result.getArguments(), contains("player1"));
    assertThat(result.getLabels(), contains("Unreg"));
  }
コード例 #6
0
  @Test
  public void shouldHandleBaseWithWrongArguments() {
    // given
    List<String> parts = singletonList("unregister");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
    assertThat(
        result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
    assertThat(result.getDifference(), equalTo(0.0));
    assertThat(result.getArguments(), empty());
    assertThat(result.getLabels(), equalTo(parts));
  }
コード例 #7
0
  @Test
  public void shouldMapPartsToCommandWithNoCaseSensitivity() {
    // given
    List<String> parts = asList("Authme", "REG", "arg1", "arg2");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(
        result.getCommandDescription(),
        equalTo(getCommandWithLabel(commands, "authme", "register")));
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.SUCCESS));
    assertThat(result.getLabels(), equalTo(parts.subList(0, 2)));
    assertThat(result.getArguments(), contains("arg1", "arg2"));
    assertThat(result.getDifference(), equalTo(0.0));
  }
コード例 #8
0
  @Test
  public void shouldPassCommandPathAsArgumentsToHelpCommand() {
    // given
    List<String> parts = asList("email", "helptest", "arg1");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.SUCCESS));
    assertThat(
        result.getCommandDescription(),
        equalTo(getCommandWithLabel(commands, "email", "helptest")));
    assertThat(result.getLabels(), contains("email", "helptest"));
    assertThat(result.getArguments(), contains("email", "arg1"));
    assertThat(result.getDifference(), equalTo(0.0));
  }
コード例 #9
0
  @Test
  public void shouldSuggestCommandWithSimilarLabel() {
    // given
    List<String> parts = asList("authme", "reh", "pass123", "pass123");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(
        result.getCommandDescription(),
        equalTo(getCommandWithLabel(commands, "authme", "register")));
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.UNKNOWN_LABEL));
    assertThat(result.getDifference() < 0.75, equalTo(true));
    assertThat(result.getLabels(), equalTo(parts.subList(0, 2)));
    assertThat(result.getArguments(), contains("pass123", "pass123"));
  }
コード例 #10
0
  @Test
  public void shouldRejectCommandWithTooManyArguments() {
    // given
    List<String> parts = asList("authme", "register", "pass123", "pass123", "pass123");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(
        result.getCommandDescription(),
        equalTo(getCommandWithLabel(commands, "authme", "register")));
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
    assertThat(result.getDifference(), equalTo(0.0));
    assertThat(result.getLabels(), equalTo(parts.subList(0, 2)));
    assertThat(result.getArguments(), equalTo(parts.subList(2, 5)));
  }
コード例 #11
0
  @Test
  public void shouldRecognizeMissingPermissionForCommand() {
    // given
    List<String> parts = asList("authme", "login", "test1");
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class)))
        .willReturn(false);

    // when
    FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);

    // then
    assertThat(
        result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "authme", "login")));
    assertThat(result.getResultStatus(), equalTo(FoundResultStatus.NO_PERMISSION));
    assertThat(result.getArguments(), contains("test1"));
    assertThat(result.getDifference(), equalTo(0.0));
    assertThat(result.getLabels(), equalTo(parts.subList(0, 2)));
    assertThat(result.getArguments(), contains(parts.get(2)));
  }