Ruang penulis
SEBUAH JURNAL TENTANG TEKNOLOGI

Belajar hal baru.
Tulis. Bagikan.

Ruang untuk merangkai pengetahuan, satu baris kode setiap hari.
Temukan tutorial, ide, dan catatan dari perjalanan belajar.

1914 catatan & terus bertumbuh
PILIHAN EDITOR
Java

Memahami Java Stream: olah koleksi dengan lebih ringkas

Pelajari alur filter, map, dan collect untuk mengolah data Java dengan kode yang mudah dibaca.

D Tim Diary Coding · 1 menit baca
UNTUK RASA INGIN TAHUMU

Catatan terbaru.

JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I mock exceptions in JUnit tests?

In JUnit tests, you usually don’t “mock” exceptions directly. Instead, you either: Assert that real code throws an exception, or Configure a mock dependency to throw an exception. 1. Assert that code throws an exception With JUnit 5, use assertThrows. import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; class MyServiceTest { @Test void shouldThrowException() { […]

Wayan · 3 menit baca
JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I verify method calls with Mockito and JUnit?

To verify method calls with Mockito and JUnit, use Mockito’s verify() method. This lets you check whether a mocked dependency method was called, how many times it was called, and what arguments were passed. 1. Basic Example Suppose you have a service that depends on a repository. public interface UserRepository { void save(User user); } […]

Wayan · 6 menit baca
JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I use @Mock and @InjectMocks with JUnit?

To use @Mock and @InjectMocks with JUnit, you typically use them with Mockito. @Mock creates a fake/mock dependency. @InjectMocks creates the class under test and injects the mocks into it. With JUnit 5, you enable Mockito using @ExtendWith(MockitoExtension.class). 1. Add Mockito dependencies Maven <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.4</version> <scope>test</scope> </dependency> <dependency> <gr...

Wayan · 4 menit baca
JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I mock dependencies in unit tests?

To mock dependencies in unit tests, you usually use a mocking framework such as Mockito. Mocking lets you test one class in isolation without running the real logic of its collaborators. Basic Mockito Example Suppose you have a service that depends on another class: @Service public class MyService { private final MyDependency dependency; public MyService(MyDependency […]

Wayan · 3 menit baca
JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I use Mockito with JUnit?

To use Mockito with JUnit, you add Mockito to your test dependencies, enable Mockito in your JUnit test class, then create mocks and define their behavior. Below is a simple JUnit 5 + Mockito example. 1. Add Dependencies Maven <dependencies> <!– JUnit 5 –> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.4</version> <scope>test</scope> </dependency> <!– Mockito Core –> <dependency> […]

Wayan · 4 menit baca
JUNIT / CATATAN</>
JUnit13 Jul 2026

How do I write tests for Java records?

Java records are compact classes designed to hold immutable data. Because records automatically provide a constructor, accessor methods, equals(), hashCode(), and toString(), testing them is usually simpler than testing ordinary classes. In most cases, you do not need to test Java’s generated record behavior directly. Instead, test: custom validation in the compact constructor custom methods […]

Wayan · 8 menit baca

Pengetahuan tumbuh ketika dibagikan.

Simpan rasa ingin tahu. Selalu ada hal baru untuk dipelajari.

Jelajahi catatan ↗
Putu Adi Guna Permana
TENTANG PENULIS

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Penulis dan pendiri Diary Coding — berbagi catatan, tutorial, dan pengalaman seputar pemrograman untuk siapa pun yang ingin terus belajar.