0

I'm writing some test classes for my services and noticed a weird behavior that happens after test results are returned. The console prints 'null' messages and no other information about tests. The tests work fine as I've tried to fail them to ensure that is the case. Is this the expected behavior?

@RunWith(MockitoJUnitRunner.class)
public class GradeServiceTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Mock
    private GradeRepository gradeRepository;

    @Mock
    private AssignmentService assignmentService;

    @InjectMocks
    private GradeService gradeService;

    private Assignment assignment;
    private Grade grade;

    @Before
    public void init() {
        assignment = new Assignment.Builder()
                .withId(0L)
                .withModuleId(0L)
                .withName("Test assignment")
                .withWeightEnabled(false)
                .withWeight(0)
                .build();
        grade = new Grade.Builder()
                .withId(0L)
                .withAssignmentId(0L)
                .withGradeType(GradeType.PERCENTAGE)
                .withGradeValue("50%")
                .build();
    }

    @Test
    public void shouldAddGrade() throws AssignmentException, GradeException {
        // GIVEN
        when(assignmentService.exists(grade.getAssignmentId())).thenReturn(true);
        when(gradeRepository.insert(any())).thenReturn(grade);

        // WHEN
        Grade addedGrade = gradeService.addGrade(grade.getAssignmentId(), grade.getType().name(), grade.getValue());

        // THEN
        assertThat(addedGrade).isEqualTo(grade);
    }

    @Test
    public void shouldNotAddGradeIfAssignmentDoesNotExist() throws AssignmentException, GradeException {
        // GIVEN
        when(assignmentService.exists(grade.getAssignmentId())).thenReturn(false);

        // EXPECT
        thrown.expect(AssignmentException.class);
        thrown.expectMessage(AssignmentErrorMessages.NOT_FOUND);

        // THEN
        gradeService.addGrade(grade.getAssignmentId(), grade.getType().name(), grade.getValue());
    }
}

I don't think this is normal behavior for each test to be printing 'null' without any other information. Could someone help me understand what is wrong with the code?

Test results:

null

null

Process finished with exit code 0
curiousdev
  • 626
  • 8
  • 24
  • 1
    is it `IDE` console ? what `IDE` are you using ? Can you show us your `POM.xml` or `build.gradle` whichever you have. – want2learn May 03 '19 at 20:02
  • interesting. you pointed me to the right direction - I had a dependency for Jupiter in my pom.xml file which I never used, and after removing it from dependencies list - 'null' printing has disappeared – curiousdev May 03 '19 at 20:05
  • that is wonderful. – want2learn May 03 '19 at 20:08

0 Answers0