Your Collectors.toMap call passed every test and threw in production. What did the code assume, and what are your options?
It assumed unique keys and non-null values. Collectors.toMap throws IllegalStateException on a duplicate key and NullPointerException on a null value, so supply a merge function that encodes a real rule, use groupingBy when duplicates are legitimate, or collect into a HashMap directly if nulls must survive.