False alarm: Assertions should not be used in production code

I don’t know exactly when it’s started to appear, but for sure it’s there for quite some time.

  • versions used:
  • code sample to reproduce:
    static final class TestContextData {
        private final long ticketsEvaluatingCount;
        private final long clientsQueuedCount;
        private final long sentMessagesCount;
        private final long privateMessagesCount;
        private final long errorsCount;

        TestContextData(final TestContext context) {
            Preconditions.checkNotNull(context, "context");
            ticketsEvaluatingCount = context.service.getTicketsEvaluating().size();
            clientsQueuedCount = context.service.getClientsQueuedSize();
            sentMessagesCount = context.service.getSentMessagesCount();
            privateMessagesCount = context.service.privateMessagesCount.get();
            errorsCount = context.service.errorsCount.get();

        TestContextData assertDiffs(final TestContextData objToSubtract, final int ticketsEvaluatingDiff,
                final int clientsQueuedDiff, final int sentMessagesDiff, final int privateMessagesDiff) {
            assertNotSame(objToSubtract, this);
            assertEquals("ticketsEvaluating", ticketsEvaluatingDiff, ticketsEvaluatingCount - objToSubtract.ticketsEvaluatingCount);
            assertEquals("clientsQueued", clientsQueuedDiff, clientsQueuedCount - objToSubtract.clientsQueuedCount);
            assertEquals("sentMessages", sentMessagesDiff, sentMessagesCount - objToSubtract.sentMessagesCount);
            assertEquals("privateMessages", privateMessagesDiff, privateMessagesCount - objToSubtract.privateMessagesCount);
            assertSame("errors", errorsCount, objToSubtract.errorsCount);
            return this;

It is a multimodule Eclipse project.

Hi @Petr_Nehez

The import of the Eclipse project may have had some issues. Please go into project structure and ensure that the src/test/java source folder is designed to be a test source:

Thanks @Julien_HENRY, it was that :+1:
Not all modules have had those folders set correctly.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.