This is a pretty straightforward way to test untestable code.This is a pretty straightforward way to test untestable code.

Testing the Untestable: A Simple Way to Handle Static Methods in Legacy Java

2025/10/24 12:22

I'm currently working on a software designed more than a decade ago. It offers a plugin architecture: you can develop a plugin whose lifecycle is handled by the software. The tough part, though, is how you access the platform capabilities: via static methods on singletons.

@Override public boolean start() { var aService = AService.getInstance(); var anotherService = AnotherService.getInstance(); // Do something with the services var result = ...; return result; }

There's no easy way to test the start() method. In the old days, Mockito developers had pushed back against this feature, and the only alternative was PowerMock. The decision was reversed in 2020 with the 3.4.0 release, which introduced static method mocking in Mockito.

I liked the previous situation better. My opinion is that having to mock static methods is a sign of badly designed code. I wrote about it already ten years ago. With PowerMock, one could mock the static methods, write the test, redesign the code, and then remove PowerMock. With the current situation, one can't look at the dependencies to search for design smells. In any case, the above problem still stands, and I can't change the design. It's forced upon me.

The solution is strangely straightforward, though. Just write a wrapper method around the one:

@VisibleForTesting //1 boolean start(AService aService, AnotherService anotherService) { //2 // Do something with the services var result = ...; return result; } @Override public boolean start() { var aService = AService.getInstance(); var anotherService = AnotherService.getInstance(); return start(aService, anotherService); //3 }

  1. Method is normally private, but since we want to test it, we make it package visible. The @VisibleForTesting annotation is for documentation purposes.
  2. The testable method has parameters that can be mocked
  3. Call the testable method

In this post, I showed how one can test legacy code not built on Dependency Injection. This is a pretty straightforward way to test untestable code.


Originally published at A Java Geek on October 19th, 2025

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact service@support.mexc.com for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.
Share Insights

You May Also Like

Dogecoin koers waarschuwing: DOGE correctie dreigt door bearish structuur

Dogecoin koers waarschuwing: DOGE correctie dreigt door bearish structuur

i Kennisgeving: Dit artikel bevat inzichten van onafhankelijke auteurs en valt buiten de redactionele verantwoordelijkheid van BitcoinMagazine.nl. De informatie is bedoeld ter educatie en reflectie. Dit is geen financieel advies. Doe zelf onderzoek voordat je financiële beslissingen neemt. Crypto is zeer volatiel er zitten kansen en risicos aan deze investering. Je kunt je inleg verliezen. @media (max-width: 700px) { .crypto-cta-banner { padding: 0 0 0 20px; font-size: 12px; } .crypto-cta-button { padding: 0 10px; font-size: 12px; } .crypto-desktop-text { display: none; } .crypto-mobile-text { display: block; } } @media (min-width: 701px) { .crypto-mobile-text { display: none; } } Connect met Like-minded Crypto Enthusiasts! Connect op Discord! Check onze Discord De Dogecoin koers lijkt zijn glans even kwijt. Ondanks een kleine plus van 1,6% naar $ 0,1976, oogt het beeld broos. De DOGE koers steeg de afgelopen week nog ruim 11%, maar op de grafiek is iets te zien wat handelaren zorgen baart. Een bearish structuur die kan wijzen op een nieuwe correctie. Wat gaat Dogecoin doen en kan de meme coin 1 dollar worden als dit patroon standhoudt? Dogecoin koers – bron: CoinMarketCap Dogecoin koers breekt door rising wedge dus verkoopsignaal Op de daggrafiek is duidelijk te zien dat de rising wedge is gebroken. Zo’n patroon ontstaat als de koers stijgt binnen twee oplopende trendlijnen die steeds dichter bij elkaar komen. Het lijkt sterk, maar het is vaak een teken dat het momentum afneemt. Zodra de onderkant breekt, volgt meestal een terugval. Dat lijkt nu ook bij Dogecoin te gebeuren. $DOGE Analysis#Dogecoin dropped over -50% during the recent crypto market downturn, but later rebounded +90% as #Bitcoin recovered. On the weekly timeframe, DOGE is hovering near a major support zone, having broken below the lower line of a rising wedge. In the coming weeks,… pic.twitter.com/R4DWUZMNiw — Protrader 365 (@protrader_365) October 22, 2025 De koers veerde de afgelopen dagen kort op, maar het herstel is zwak. Kopers raken sneller uitgeput en verkopers nemen het over bij elke kleine stijging. De DOGE koers stuitert al dagen tegen dezelfde weerstand rond $ 0,20 – $ 0,21. Lees ook ons artikel over Shiba Inu dat crasht, maar beleggers houden hoop. Steunzone Dogecoin koers op $ 0,1515 in zicht De belangrijkste steun ligt bij $ 0,1515. Een niveau dat eerder standhield tijdens de paniekverkoop van oktober. Als de koers daaronder zakt, kan Dogecoin verder terugvallen richting $ 0,14. Die zone is cruciaal voor het vertrouwen. Een slot onder dat punt zou het bearish beeld bevestigen. Steun en Weerstand Dogecoin koers – bron: TradingView Op korte termijn is het volume gedaald, terwijl de RSI in het middengebied blijft hangen. Dat betekent dat er nog ruimte is voor een daling zonder dat de crypto oversold is. De MACD ligt nog op de signaallijn, wat duidt op zwak momentum. Kortom, de technische kant oogt fragiel. Bekijk hier de Dogecoin koersverwachting voor de lange termijn. RSI + MACD Dogecoin koers – bron: TradingView Beleggersvertrouwen brokkelt af Het beeld bij Dogecoin past bij wat we ook in de rest van de memecoin markt zien, namelijk minder hype, minder volume, en beleggers die voorzichtig worden. De laatste weken is er weinig nieuws dat de crypto echt omhoog duwt. Institutionele interesse, zoals bij de DOGE ETF, is afgekoeld. Sinds de eerste weken van notering komen er nauwelijks nieuwe instromen bij. Dat vertelt iets over het vertrouwen in de coin. Zonder nieuwe verhalen of sterke marktgroei is het lastig om een stevige rally te starten. Wat gaat Dogecoin doen? Zolang de koers onder de $ 0,21 blijft, is het risico op een nieuwe correctie groot. Het sentiment blijft zwak en er is nog geen teken van een echte trendomslag. Breekt de koers met kracht boven die grens, dan kan de koers opveren naar $ 0,24 of zelfs $ 0,27. Maar daarvoor moet het handelsvolume aantrekken en dat ontbreekt nu. Dogecoin $DOGE must defend $0.18. Hold it, and the path to $0.25 or $0.33 opens up. pic.twitter.com/fbbnK4M6Mu — Ali (@ali_charts) October 24, 2025 Traders kijken daarom vooral naar de steun op $ 0,1515. Als dat niveau standhoudt en de markt weer aantrekt, kan er een herstel volgen. Maar een doorbraak omlaag zou het vertrouwen verder onder druk zetten. Kan Dogecoin 1 dollar worden? De droom van Dogecoin op 1 dollar leeft nog altijd, maar voorlopig lijkt dat ver weg. Daarvoor is een sterke bullmarkt nodig met veel liquiditeit en hype, omstandigheden die nu ontbreken. De meme coin heeft eerder bewezen dat het snel kan stijgen als de markt omslaat, maar op dit moment mist DOGE dat momentum volledig. Voor de liefhebbers hebben we een lijst samengesteld met de beste meme coins voor de aankomende rally. Voor nu draait alles om stabiliteit. Als de koers boven $ 0,15 weet te blijven en het marktsentiment verbetert, kan er langzaam weer ruimte ontstaan voor groei. De Dogecoin koers staat op een kruispunt De Dogecoin koers beweegt in een lastige fase. De breuk van de rising wedge, het dalende volume en de zwakke indicatoren wijzen op risico voor houders. Zolang de koers onder de $ 0,21 blijft, blijft de trend neerwaarts gericht. Voor handelaren is het moment om alert te blijven. De zone rond $ 0,1515 wordt de echte test. Houdt die steun, dan is een herstel mogelijk. Zakt de koers eronder, dan kan de volgende daling sneller komen dan veel beleggers hopen. Opvolger van Dogecoin Nu Dogecoin op een belangrijk punt staat, is het een interessant moment om te kijken naar de opvolger van Dogecoin, die nog in de presale zit en een fanatieke community heeft opgebouwd. De meest explosieve winsten heeft Dogecoin al achter zich liggen en daarom richten investeerders zich nu op Maxi Doge ($MAXI). Call me the MAXIBLE HULK. pic.twitter.com/GfpObOjNcM — MaxiDoge (@MaxiDoge_) October 22, 2025 $MAXI is het laatste lid van de Doge familie en is speciaal voor degene die de eerste rally’s van DOGE, WIF en SHIB gemist heeft. Het neefje van DOGE zit vol met pre-workout, Red Bull, testosteron en 1000x leverage. Als vroege investeerder kun je nu al je $MAXI tokens staken tegen het jaarlijkse rendement van 81%. Dit is al massaal gedaan en er staan al meer dan 9 miljard $MAXI token vast. Je hebt nog even de tijd om je eerste $MAXI tokens te bemachtigen voor de huidige lage prijs. Bij elke nieuwe fase van de presale hoort namelijk ook een nieuwe prijsverhoging. Nu naar Maxi Doge i Kennisgeving: Dit artikel bevat inzichten van onafhankelijke auteurs en valt buiten de redactionele verantwoordelijkheid van BitcoinMagazine.nl. De informatie is bedoeld ter educatie en reflectie. Dit is geen financieel advies. Doe zelf onderzoek voordat je financiële beslissingen neemt. Crypto is zeer volatiel er zitten kansen en risicos aan deze investering. Je kunt je inleg verliezen. Het bericht Dogecoin koers waarschuwing: DOGE correctie dreigt door bearish structuur is geschreven door Christiaan Kopershoek en verscheen als eerst op Bitcoinmagazine.nl.
Share
2025/10/25 05:31
Here’s What To Know About H-1B Visas—As Trump Adds $100,000 Fee

Here’s What To Know About H-1B Visas—As Trump Adds $100,000 Fee

The post Here’s What To Know About H-1B Visas—As Trump Adds $100,000 Fee appeared on BitcoinEthereumNews.com. Topline President Donald Trump issued a proclamation that would impose an annual $100,000 fee on H-1B visa applications, used by companies to hire skilled workers from abroad, in a possible roadblock for the U.S. tech industry while disrupting the hiring process for firms like Amazon, Apple and Google. Earlier fees to assist specialty workers were as low as $215. Copyright 2025 The Associated Press. All rights reserved Key Facts The H-1B visa program, established through the Immigration Act of 1990 under former President George H.W. Bush, allows U.S.-based companies to temporarily employ foreign workers in occupations requiring a “body of highly specialized knowledge” and a bachelor’s degree or higher. Industries eligible under the H-1B visa program include fashion modeling, medicine, engineering, finance, computer science and architecture, among others, in addition to participants in Defense Department projects, according to the State Department. An employer files H-1B petitions with the Labor Department on the worker’s behalf, known as an I-29 and, if approved, the worker then applies for a visa before entering the U.S. Employers can also apply through a lottery system, as there’s an annual cap of about 85,000 visas for most private companies, and existing program fees include $215 to register for the lottery and $780 for the petition. The maximum period granted for H-1B workers is six years, though employers may request to extend the visa’s status on three-year increments, if eligible. Big Number 20%. That’s the estimated percentage of H-1B applications approved each year, according to a study from the National Foundation for American Policy, a public policy nonprofit. What Companies Hire The Most Workers With H-1b Visas? Amazon employed the most workers (10,044) using H-1B visas as of June 30, followed by Tata Consultancy Services (5,505), Microsoft (5,189), Meta (5,123), Apple (4,202) and Google (4,181), according to…
Share
2025/09/21 01:00