<fim-prefix> private P2PNetwork p2PNetwork;

  @Before
  public void before() {
    this.method = new NetListening(p2PNetwork);
  }

  @Test
  public void shouldReturnTrueWhenNetworkIsListening() {
    when(p2PNetwork.isListening()).thenReturn(true);

    final JsonRpcRequestContext request = netListeningRequest();
    final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, true);

    Assertions.assertThat(method.response(request))
        .isEqualToComparingFieldByField(expectedResponse);
  }

  @Test
  public void shouldReturnFalseWhenNetworkIsNotListening() {
    when(p2PNetwork.isListening()).thenReturn(false);

    final JsonRpcRequestContext request = netListeningRequest();
    final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, false);

    Assertions.assertThat(method.response(request))
        .isEqualToComparingFieldByField(expectedResponse);
  }

  @Test
  public void getPermissions() {
    List<String> permissions = method.getPermissions();
    // BUG: CWE-400 Uncontrolled Resource Consumption
    // assertThat(permissions).containsExactlyInAnyOrder("net:*", "net:listening", "*:*");
    // FIXED: 
<fim-middle>    assertThat(permissions).containsExactly("*:*", "net:*", "net:listening");
  }

  private JsonRpcRequestContext netListeningRequest() {
    return new JsonRpcRequestContext(new JsonRpcRequest("2.0",<fix-suffix> "net_listening", new Object[] {}));
  }
}
<|endoftext|>