Screenshot by Sally Neiman/CNET

T-Mobile and Dish are working toward the same goal of getting T-Mobile's $26.5 billion merger with Sprint across the finish line, but four years ago the wireless carrier and satellite TV provider nearly partnered up themselves. In discussing the carrier's turnaround from its dire conditions, T-Mobile CEO John Legere revealed just how close the two providers were to a deal of their own in 2015.

Legere, who testified on Thursday in a trial to determine the fate of the T-Mobile-Sprint deal, was the first witness called by T-Mobile in its defense of the merger. His testimony included some of his company's "un-carrier" moves and an account of how he was able to turn around the network following the failed AT&T and T-Mobile merger in 2011. Appearing in a dark suit with a tie -- unusual for the man known for his magenta tees and leather jacket -- Legere detailed his company's troubled state when he took over in 2012, citing its fourth-place position in the US wireless market, limited spectrum and high rate of customers leaving for other carriers.

Legere credited the carrier's self-proclaimed "un-carrier" approach to the wireless industry -- including its removal of two-year contracts and overages and bringing back unlimited plans -- for helping engineer the turnaround while also acknowledging the importance of the $3 billion in cash and billions of dollars worth of spectrum that AT&T gave T-Mobile as part of the "breakup fee" from their failed deal.

The possible deal between Dish and T-Mobile and their unlikely partnership now underscores the incestuous nature of the wireless business, with a near decades-long soap opera involving most of the major wireless players, including AT&T, T-Mobile, Sprint, as well as satellite TV provider Dish. AT&T's money and spectrum allowed T-Mobile to purchase Metro PCS, build an LTE network and acquire additional spectrum such as its purchase of airwaves from Verizon in 2014.

If T-Mobile's merger with Sprint doesn't go through, there will be no lucrative breakup fee. Instead, the breakup fee would see T-Mobile pay Sprint $600 million, though even that number may vary, depending on exactly how the deal falls apart.

Legere continued arguing T-Mobile's case that it needs Sprint to be able to boost its network's capacity allowing for faster speeds and cheaper prices for consumers due to the "highly complementary" nature of each carrier's wireless spectrum.

By combining with Sprint, T-Mobile has said it will be able to offer a vastly superior network with "triple the total 5G capacity of standalone T-Mobile and Sprint combined." Without the deal and the spectrum capacity it would bring, T-Mobile's network could "exhaust capacity in the next two to four years" in certain markets, according to an enterprise risk assessment that was presented in court.

The 14 state attorneys general who are suing to block the deal, however, argue the elimination of a fourth competitor would cause prices to rise and hurt consumers.

A near Dish/T-Mobile pair up

That's where Dish comes in. As part of its agreement with the Department of Justice, Dish will acquire divested Sprint assets from T-Mobile should the deal go through including the Boost prepaid brand, wireless spectrum, retail stores as well the ability to use T-Mobile's network for seven years while it built out its own 5G network.

In discussing possible partners that could replace Sprint, Legere said that Dish was more interesting given the TV provider's "spectrum trove" that is "roughly the size of Verizon's" as opposed to having a cable company like Comcast and Charter acquire the assets.

In their questioning of Legere, the lawyers representing the attorneys general looking to block the deal questioned why T-Mobile needed to partner with Sprint, specifically, as opposed to dealing with Dish. Legere recommended a merger with Dish to his board in 2015 with the outspoken T-Mobile CEO saying he liked the idea of "un-carriering" Dish's satellite business as well as getting access to Dish's spectrum.

The two parties, however, couldn't agree on a price, with Legere recalling that Dish co-founder Charlie Ergen believed that T-Mobile would "disintegrate" and have its stock fall below $20 as opposed to the $25 price the stock was trading at when the deal was discussed. Ergen, a notoriously difficult negotiator, is expected to appear in court next week.

When asked if he would call Dish should the Sprint deal be blocked, Legere said he wasn't sure what he would do.

The T-Mobile CEO is expected to continue his testimony Friday morning, with T-Mobile President and Chief Operating Officer Mike Sievert also expected to testify.