You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by James Stauffer <st...@gmail.com> on 2006/02/02 17:30:49 UTC
Re: unit test decide(LoggingEvent inEvent)
If you check the source code of the other filters do they have unit
tests that would work as examples?
On 2/1/06, Kamal Ahmed <KA...@webmethods.com> wrote:
> Hi,
> Could you please give me some CLUE, on how to proceed to test the following
> method:
> public int decide(LoggingEvent inEvent) {
>
> boolean retCode = false;
>
> if (inEvent != null) {
>
> Matcher matcher =
> targetPattern.matcher(inEvent.getLoggerName());
>
> retCode = (matcher.find() == acceptMatch);
>
> }
>
> return (retCode) ? Filter.NEUTRAL : Filter.DENY;
>
> }
>
> Now i need to write a junit test for this, but I am not sure WHERE to start?
>
> 1. Should i create a NEW instance of the class this method belongs to?
>
> 2. How do i get an "inEvent" of type LoggingEvent?
>
> 3. So this is how i have started writing test case for the method, decide(),
> based on:
>
> The General form of Junit test follows the following steps:
>
> 1. Create an object and put it in a known state
> 2. Invoke a method which returns the "actual result"
> 3. Create the "expected result" which may be a primitive value or a more
> complex object.
> 4. Invoke "assertEquals(expectedResult,actualResult)
>
>
>
> public int testdecide() {
> int result=0;
>
> // WmLoggerFilter subjectWmLoggerFilter = new
> WmLoggerFilter();
>
> return result;
> }
> Since WmLoggerFilter is the class that contains testdecide()
> I would appreciate any help.
> Thanks,
>
> -Kamal.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org