Skip to content

Commit

Permalink
Merge pull request #52 from seeseemelk/docs/improve-docs
Browse files Browse the repository at this point in the history
Fix incorrect code blocks
  • Loading branch information
seeseemelk committed Apr 19, 2020
2 parents 7ec8506 + 42e83b1 commit a7184b0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 48 deletions.
24 changes: 12 additions & 12 deletions docs/entity_mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ Mock Entities
=============
The EntityMock adds several methods that can be used be on all entities created by MockBukkit.

This will check that the entity is within a certain distance from the location.
::
This will check that the entity is within a certain distance from the location. ::

entity.assertLocation(location, distance);

You can also assert that a player was teleported by a plugin.
::
You can also assert that a player was teleported by a plugin. ::

entity.assertTeleported(location, distance);
entity.assertNotTeleported();

If you want to reset the teleported flag you can use
::
If you want to reset the teleported flag you can use ::

entity.clearTeleported();

This will useful if you know that a method teleports your entity and you want to check if afterwards a different method *doesn't* teleport it.

To check if the entity was teleported without throwing AssertionExceptions use:
::
To check if the entity was teleported without throwing AssertionExceptions use::

if (entity.hasTeleported())
{
// Player was teleported
}

In normal bukkit the only way to move an entity is by teleporting it, but this causes a teleported event.
Therefore MockBukkit adds a setter for the location
::
Therefore MockBukkit adds a setter for the location::

entity.setLocation(location);

In MockBukkit an entity can also be renamed if needed
::
In MockBukkit an entity can also be renamed if needed::

entity.setName("new-name");

An EntityMock also implements the [MessageTarget](MessageTarget.md) interface so one can test received messages.
Expand Down
7 changes: 3 additions & 4 deletions docs/first_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ This is because the ``JavaPlugin`` class expects that the plugin was loaded by a
special class loader.
However, it is not possible to use this class loader during the unit test phase.

The workaround is easy though, a constructor with a visibility of ``protected``.
The workaround is easy though, a constructor with a visibility of ``protected``. ::

::
public class MyPlugin extends JavaPlugin {
public MyPlugin() {
super();
Expand All @@ -42,8 +41,8 @@ The workaround is easy though, a constructor with a visibility of ``protected``.

Creating the Test Class
^^^^^^^^^^^^^^^^^^^^^^^
Once your directories are set up, you can create unit tests like this:
::
Once your directories are set up, you can create unit tests like this::

public class MyPluginTests {
private ServerMock server;
private MyPlugin plugin;
Expand Down
21 changes: 11 additions & 10 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Dependencies
^^^^^^^^^^^^
To enable unit testing, all you need to do is add the JUnit dependency and the
correct MockBukkit dependency.
Here is an example which adds support for JUnit 4.12 and MockBukkit-v1.15:
::
Here is an example which adds support for JUnit 4.12 and MockBukkit-v1.15::

repositories {
mavenCentral()
Expand All @@ -36,19 +35,20 @@ Here is an example which adds support for JUnit 4.12 and MockBukkit-v1.15:
Running
^^^^^^^
When this has been added, you can run your tests using the `test` task.
For Windows, running the following command will execute the tests:
::
For Windows, running the following command will execute the tests::

gradlew.bat test
On Linux and macOS, use the following command:
::

On Linux and macOS, use the following command::

./gradlew test

Maven
-----
For people that use Maven instead of Gradle can also use MockBukkit by adding it
to their `pom.xml`.
To do so, both JUnit and MockBukkit habe to be added to your dependencies:
::
To do so, both JUnit and MockBukkit habe to be added to your dependencies::

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -77,6 +77,7 @@ To do so, both JUnit and MockBukkit habe to be added to your dependencies:

Running
^^^^^^^
After having modified your `pom.xml`, you can run the unit tests as follows:
::
After having modified your `pom.xml`, you can run the unit tests as follows::

mvn test

8 changes: 4 additions & 4 deletions docs/message_target.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Two examples of message targets are ```ConsoleCommandSenderMock``` and ```Entity

Using MessageTarget
-------------------
Any message that was sent to the target can be read using
::
Any message that was sent to the target can be read using::

SimpleEntityMock entity = new SimpleEntityMock();
entity.sendMessage("Hello world!");
String message = entity.nextMessage();

It also contains two assert methods to check if a message was or wasn't received.
::
It also contains two assert methods to check if a message was or wasn't received. ::

entity.sendMessage("Hello world!");
entity.assertSaid("Hello world!");
entity.assertNoMoreSaid();
Expand Down
22 changes: 12 additions & 10 deletions docs/player_mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ Adding a player
===============
MockBukkit has several methods to add player to the test server.

This method creates a random new player and lets it join the server.
::
This method creates a random new player and lets it join the server. ::

PlayerMock player = server.addPlayer();

If you want to customise the object before adding it (such as setting a user name), this can be used:
::
If you want to customise the object before adding it (such as setting a user name), this can be used::

PlayerMock player = server.addPlayer(player)

One can also add a UUID after the username if needed.

And lastly, if you want to add a whole bunch of players quickily, consider using:
::
And lastly, if you want to add a whole bunch of players quickily, consider using::

server.setPlayers(20);

This will add 20 players to the server.
After this command you can use ```server.getPlayer(index)``` to reference each player in an easy way.

# PlayerMock methods
The PlayerMock class adds several methods that makes unit testing player related methods nicer.
In all examples we will assume that your unit test starts with:
::
In all examples we will assume that your unit test starts with::

PlayerMock player = server.addPlayer();

It's possible to assert that a player is in a specific gamemode.
If the player is not in that gamemode, an AssertionException is thrown.
::
If the player is not in that gamemode, an AssertionException is thrown. ::

player.assertGameMode(GameMode.SURVIVAL);

PlayerMock extends [EntityMock](EntityMock.md) since it's possible to use those added methods too.
Expand Down
12 changes: 6 additions & 6 deletions docs/scheduler_mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ This schedulers is used in the same way as a normal scheduler except that it add

Executing ticks
---------------
The scheduler can be asked to perform a single tick during tick.
::
The scheduler can be asked to perform a single tick during tick. ::

server.getScheduler().performOneTick();

If more ticks need to be executed in quick succession, it's possible to execute many ticks at once.
The following code will perform a hundred ticks.
::
The following code will perform a hundred ticks. ::

server.getScheduler().performTicks(100L);

Using this method executes all ticks in order, as if they were executed on a real server.

Getting the current tick.
-------------------------
MockBukkit has an extra method that allows to get the number of ticks since MockBukkit was last started.
::
MockBukkit has an extra method that allows to get the number of ticks since MockBukkit was last started. ::

long tick = server.getScheduler().getCurrentTick();
4 changes: 2 additions & 2 deletions docs/world_mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Often times one needs to interact with the minecraft world.
MockBukkit always the creation of superflat worlds on the fly.
Each block in the world is generated the moment it is accessed for the first time, so creation new worlds is a very cheap operation.

The following code will create a flat world:
::
The following code will create a flat world::

WorldMock = server.addSimpleWorld("my_world");

Every time MockBukkit is started a world called "world" is automatically created.
Expand Down

0 comments on commit a7184b0

Please sign in to comment.