---
schema_version: "1"
id: d483cdcf00311248181aca7f9eac80c9cee3670dc4022e034b30f6ece18d0fd6
title: MUnit Run Custom Event Processor
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/latest/run-custom-event-processor.md
canonical_url: https://docs.mulesoft.com/munit/latest/run-custom-event-processor
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4bbccb1d71ff03c75e330790c1639ecca4eaa6cbe678d20711d19c59a0054351
description: MuleSoft Documentation Site
release: "3.7"
latest: true
---
---
product: MUnit
version: 3.7
is-latest-version: true
keywords: mule, esb, tests, qa, quality assurance, verify, functional testing, unit testing, stress testing
---

# MUnit Run Custom Event Processor

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

The MUnit Run Custom event processor runs a custom Java assertion class against a Mule event during
a MUnit test. Use it when built-in matchers are not sufficient and you need to implement custom
validation logic in Java.

To add the **Run Custom processor** to your project, add the following dependency to your `pom.xml`
file:

```xml
<dependency>
    <groupId>com.mulesoft.munit</groupId>
    <artifactId>munit-assert</artifactId>
    <version>${munit.version}</version>
    <scope>test</scope>
</dependency>
```

You also have to add your custom assertion class to the `mule-artifact.json` file as an exported
resource.

For example, you can define the following assertion in Java:

```java
package org.mule.custom;
import org.mule.munit.assertion.api.MunitAssertion;
import org.mule.munit.assertion.api.TypedValue;

public class CustomAssertion implements MunitAssertion {

    @Override
    public void execute(TypedValue expression, Object params) throws AssertionError { (1)
        if (!"Hello World".equals(expression.getValue())) { (2)
            throw new AssertionError("Error the payload is incorrect");
        }
     }

}
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Implement the only method in the interface <code>public void execute(TypedValue expression, Object params) throws AssertionError</code>.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Run your custom logic, which in this case validates that the message payload is <code>Hello World</code>.</td></tr></tbody></table>

The `CustomAssertion` class must be located in the scr/test/java directory.

And use the **Run Custom Event Processor** to run it:

```xml
<munit-tools:run-custom
  assertion="org.mule.custom.CustomAssertion" (1)
  expression="#[payload]"/>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>The assertion field needs to have the canonical class name of your custom assertion and the class needs to be exported.</td></tr></tbody></table>

To export it when packaging your application, add the `org.mule.custom` package to your
`mule-artifact.json`

```json
{
  "name": "mule-application",
  "minMuleVersion": "4.2.0",
  "classLoaderModelLoaderDescriptor": {
    "id": "mule",
    "attributes": {
      "exportedPackages": ["org.mule.custom"]
    }
  }
}
```

> [!NOTE] You only need to configure the package name in the `exportedPackages` collection.

## See Also

- [MUnit Matchers](https://docs.mulesoft.com/munit/latest/munit-matchers)

- [Assert That Event Processor](https://docs.mulesoft.com/munit/latest/assertion-event-processor)

- [Set Event Processor](https://docs.mulesoft.com/munit/latest/set-event-processor)

- [Mock When Event Processor](https://docs.mulesoft.com/munit/latest/mock-event-processor)

- [Verify Event Processor](https://docs.mulesoft.com/munit/latest/verify-event-processor)

- [Fail Event Processor](https://docs.mulesoft.com/munit/latest/fail-event-processor)
