539. HaTov v'haMeitiv and Dayan Ha'Emes
Brachos 10:3
When a person receives good news, he recites the bracha “Blessed are You, Hashem our God, King of the universe, Who is good and Who does good.” If one receives bad news, he recites the bracha that God is “the true Judge.” One must recite the bracha over unfortunate occurrences with the positive mood that he has when reciting the bracha over desirable outcomes. Deuteronomy 6:5 says, “You shall love Hashem your God...with all your might.” This includes praising God with joy even when times are hard.
Brachos 10:4
When a positive thing happens to a person or he receives good news, even though it seems that the positive thing will ultimately lead to a negative consequence, he nevertheless recites the bracha that God is good and does good. Similarly, if something bad happened or one received bad news, even though it seems that this negative thing will ultimately lead to a positive outcome, one still recites the bracha that God is the true Judge. Brachos depend on the current situation, not potential future consequences.