What led to the case of Marbury v. Madison?

1.the Midnight Judges Act eliminating key federal positions
2.President James Madison issuing a writ of mandamus
3.Congress passing the Judiciary Act of 1789
4. Adams quickly appointing federal positions at the end of his term