An employee pours milk into a cardboard coffee cup inside a Starbucks coffee shop in London on Monday, June 9, 2014. © Jason Alden, Bloomberg via Getty Images

When Dunkin' Donuts began selling lattés and other premium coffee drinks around a decade ago, it was viewed as a direct attack on Starbucks (SBUX) the nation's leading specialty coffee chain.

Then five years ago, another front broke out in the java wars when McDonald's (MCD) formally launched its McCafé line of premium coffee drinks. At the time, Mickey D's entry into this brewing battle was called "a game changer" -- and not in a good way for Starbucks.

The pincer moves were seen as a real threat to the Seattle-based java juggernaut, especially given the economics of the time. In 2009, the economy was still mired in a recession stemming from the global financial crisis. And with unemployment hovering near 10 percent, conventional wisdom said that cost-conscious consumers were likely to make a shift away from Starbucks' pricey menu toward more cost-conscious offerings found at McDonalds or Dunkin'.

Research, in fact, showed that while coffee purchases were relatively recession proof -- if you have to have your morning fix, you have to have your fix -- the amount of money consumers were willing to spend per visit was likely to fall in economically troubled times. Hence, McDonald's and Dunkin', which both cater to working- and middle-class households, saw an opening.

Yet if the past five years have taught us anything, it's that conventional wisdom was wrong.

As the chart below shows, over the past five years, Starbucks' same-store sales -- that is, revenues at locations that have been open for more than a year -- accelerated and far outpaced those of Dunkin' Brands (DNKN), parent company of Dunkin' Donuts.

Same-store growth rates at Starbucks and Dunkin Donuts

This point was reinforced when Starbucks announced its latest quarterly results in July, which showed better-than-expected profits, and an 11 percent jump in overall revenues versus the same period last year.

What gives?

Well, class may indeed be playing a role in the coffee wars -- but not in the way that you may have assumed. Earlier this year, Ted Cooper at The Motley Fool made an astute point: "McDonald's may be able to sell coffee, but it will never come close to replicating Starbucks' menu. McDonald's best shot at becoming a coffee destination is to go after the price-conscious coffee crowd."

And who owns that crowd? Dunkin' Donuts, of course, which despite its name generates nearly 60 percent of its revenues from coffee and beverage sales, not doughnuts.

The fact that Dunkin's same-store sales growth pace has sunk precipitously ever since McCafés hit the market -- even as the economy improved -- is likely due to McDonald's marketing push for bargain-seeking coffee drinkers. In many markets, in fact, McDonald's is offering any size hot coffees for $1, which is more than half off what Dunkin' charges for a hot regular cup of Joe.

Not surprisingly, investors have caught onto the fact that McDonald's and Dunkin' may be hurting one another -- and not Starbucks -- as evidenced by recent moves in Starbucks, Dunkin' and McDonald's shares.

The economy strikes back

Meanwhile, the premium status that Starbucks maintains is likely to work to its advantage as the economy improves.

For instance, Dunkin' Donuts recently announced that it will have to raise its prices slightly to address skyrocketing coffee bean prices in the commodity market. It remains to be seen how those price hikes will affect its consumers' purchasing habits.

At Starbucks, it's already known how consumers will react. When the company announced a price hike in 2013, comp-store sales remained strong as consumers cherished the brand enough to pay up, even in a so-so economy. The company announced another price hike in June, which is likely to add to overall revenues going forward.

The empire strikes back

Ironically, the difficulties that McDonald's and Dunkin' Donuts have run into in their attempts to strike at Starbucks has created an opening for Starbucks to attack those competitors where they live -- in food sales.

Starbucks' chief financial officer Troy Alstead noted that in the company's recently ended quarter -- when same store sales rose 6 percent globally and 7 percent in the U.S. -- two percentage points of those comp sales growth was attributable to food sales.

Starbucks' momentum in food has recently been driven by increased lunch offerings, but going forward, the full effects of the company's 2012 purchase of La Boulange bakery should start showing their effects.

In a conference call with analysts last month, CEO Howard Schultz noted that La Boulange-branded baked goods are now available in more than 1,000 Starbucks stores in California and the Pacific Northwest. By the end of this summer, that number should jump to more than 2,500 stores, he said, as La Boulange food items will be sold in stores in New York, Los Angeles, Chicago and Boston.

Click here to become a fan of MSN Money on Facebook

More from Money