Created
December 10, 2022 00:50
-
-
Save lcs-felix/f692e4ec8f1fd6cc29ff51c1298fd801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Repository | |
public class AddressRepository { | |
List<Address> findAll() { | |
return List.of(new Address("a"), new Address("b")); | |
} | |
} | |
record Address(String street) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootTest | |
class AddressRepositoryTest { | |
@Mock | |
private AddressRepository addressRepository; | |
@InjectMocks | |
private AddressService addressService; | |
@BeforeEach | |
void setUp() { | |
MockitoAnnotations.openMocks(this); | |
} | |
@Test | |
void test() { | |
when(addressRepository.findAll()).thenReturn(List.of(new Address("Rua Vergueiro"))); | |
var all = addressService.findAll(); | |
System.out.println(all); | |
Assertions.assertEquals(1, all.size()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class AddressService { | |
private final AddressRepository addressRepository; | |
public AddressService(AddressRepository addressRepository) { | |
this.addressRepository = addressRepository; | |
} | |
List<Address> findAll() { | |
return this.addressRepository.findAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment