<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>java on Diogo Moreira</title><link>https://diogomoreira.dev/tags/java/</link><description>Recent content in java on Diogo Moreira</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sun, 18 Feb 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://diogomoreira.dev/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Sealed and Final in Java 17+</title><link>https://diogomoreira.dev/blog/sealed-and-final-in-java-17/</link><pubDate>Sun, 18 Feb 2024 00:00:00 +0000</pubDate><guid>https://diogomoreira.dev/blog/sealed-and-final-in-java-17/</guid><description>&lt;p&gt;Java 17 brought the &lt;strong&gt;Sealed Classes&lt;/strong&gt; feature, which allows greater control over how to structure a project&amp;rsquo;s class hierarchy. In this post, we&amp;rsquo;ll discuss this feature that permits classes and interfaces to have more control over their allowed subtypes.&lt;/p&gt;
&lt;p&gt;The keywords &lt;code&gt;sealed&lt;/code&gt;, &lt;code&gt;non-sealed&lt;/code&gt; and &lt;code&gt;permits&lt;/code&gt; are the ones to be used in the syntax of sealed classes in Java. When we mark a class as &lt;code&gt;sealed&lt;/code&gt;, it is as if we were marking it as &lt;code&gt;final&lt;/code&gt;, which does not allow other classes to extend it. So, we add classes that can extend a sealed class with the help of &lt;code&gt;permits&lt;/code&gt; keyword and then we list the permitted classes.&lt;/p&gt;</description></item><item><title>Mocking Google Cloud Storage Objects with Java</title><link>https://diogomoreira.dev/blog/mocking-google-cloud-storage-blob-objects/</link><pubDate>Sun, 10 Dec 2023 00:00:00 +0000</pubDate><guid>https://diogomoreira.dev/blog/mocking-google-cloud-storage-blob-objects/</guid><description>&lt;p&gt;Google Cloud Storage is widely used as a cloud storage service to allow users to store and retrieve objects. When working with it, it&amp;rsquo;s essential to write efficient unit tests to ensure the application behaves as expected.&lt;/p&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;One common challenge in unit testing is dealing with external dependencies, that&amp;rsquo;s when we use &lt;a href="https://stackoverflow.com/questions/2665812/what-is-mocking"&gt;&lt;em&gt;mocks&lt;/em&gt;&lt;/a&gt; such as Blob Objects from Google Cloud Storage, which may not be readily available during testing or needs to be mocked due to &lt;em&gt;pricing restrictions&lt;/em&gt;. This blog post will explore how to mock Blob Objects from &lt;strong&gt;Google Cloud Storage&lt;/strong&gt; for efficient unit testing.&lt;/p&gt;</description></item></channel></rss>