Skip to content

Support mixed boxed and unboxed primitives in assertEquals() & assertNotEquals()  #1638

@ridono

Description

@ridono

Overview

Asserting that an int equals an Integer is not possible with assertEquals() due to the compiler not knowing if it should use assertEquals(int, int) or assertEquals(Object, Object).

This results in the compile error The method assertEquals(int, int) is ambiguous for the type Assertions like in the following example:

	@Test
	void test_parseYear() throws Exception {
		Integer parsedYear = SeparateDateParser.parseYear("2014");
		Assertions.assertEquals(2014, parsedYear); // does not compile
	}

Instead you either have to declare another variable:

	@Test
	void test_parseYear() throws Exception {
		Integer parsedYear = SeparateDateParser.parseYear("2014");
		Integer expectedYear = 2014;
		Assertions.assertEquals(expectedYear, parsedYear);
	}

or use a custom assertion method:

	void assertEquals(Number expected, Number actual) {
		Assertions.assertEquals(expected, actual);
	}

We have already encapsulated this method in a utility class to reuse it in our projects, but as this is a quite common case it would be nice if the framework could provide an assertEquals() method like the one above.

Related Issues

Deliverables

  • Support mixed boxed and unboxed primitives in assertEquals()
  • Support mixed boxed and unboxed primitives in assertNotEquals()
  • Document in Release Notes

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions