Bo Yi and Yi Yin were two legendary sages in Chinese history. Since Bo Yi lived in the Xia Dynasty and Yi Yin in the Shang Dynasty, their historical existence is impossible to establish, to say the least.
It is not their historical accomplishments that I wish to talk about, but rather how they are used as an example in the Mencius. Mencius comments that Bo Yi would refuse to serve a sovereign that had any moral defects at all, and would feel like being friends with a person at all debased. He was even a bit prudish, refusing to talk with someone whose "hat was not on straight". Yi Yin, on the other hand, felt that "any government he served was that much better", and thus would serve a ruler, no matter how corrupt, as long as he thought he could help anyone at all.
Mencius says that both of these men were indeed sages, and thus there behavior was correct in each case. (He did state that Confucius, who was in the middle, was even more sagely). This statement was Mencius' way of saying that whether or not to serve a particular government at any time was up to the particular scholars situation, morals and even temperment.
An understanding of this will explain why, for example, Chu Yuan threw himself into the ocean because he could not find an honest ruler; and why Zhou En-lai was willing to serve the brutal communist government of China even during the cultural revolution, as long as he could help anyone at all.