1

I want to test this piece of block mainly in x != null, is there a better way to assert this method in JUnit.

private void myorder()
{
    if (x != null)
    {
        //some code
        myorder(x.getDown());
        System.out.print(r.getData() + " ");
        myorder(x.getUp());
    }
}

Here's what I've done so far:

@Test
assertFalse(x != null); 
Mark McElroy
  • 373
  • 4
  • 8
  • I'm not sure there's enough information to understand your problem. If you are trying to test the code within the `if (x != null) { ... }` code block then just set x to a non-null value in your test method. Likewise if you want to test the `myOrder()` method without the `if (x != null) { ... }` code block, then set `x = null` in the test. – Mark McElroy Aug 16 '20 at 05:13

1 Answers1

2

I would use Assertions class.

import static org.junit.jupiter.api.Assertions.assertNotNull;

assertNotNull(x);
Traycho Ivanov
  • 2,887
  • 14
  • 24