Skip to content

Instantly share code, notes, and snippets.

View theboreddev's full-sized avatar
💭
💻

The Bored Dev theboreddev

💭
💻
View GitHub Profile
@theboreddev
theboreddev / isRedUnsafe.java
Last active June 9, 2020 19:51
isRedUnsafe
private boolean isRed(String color) {
return color.equals("RED");
}
@theboreddev
theboreddev / isRedSafe.java
Last active June 9, 2020 19:54
isRedSafe
private boolean isRed(String color) {
return "RED".equals(color);
}
static class Customer {
private final String firstName;
private final String surname;
private final Optional<Integer> age;
private final Optional<String> address;
private final Optional<String> phoneNumber;
private final Optional<Sex> sex;
public Customer(String firstName, String surname, Optional<Integer> age, Optional<String> address, Optional<String> phoneNumber, Optional<Sex> sex) {
final Customer testCustomer = new Customer(
"John",
"Smith",
Optional.of(30),
Optional.of("Flat 0, Some Street, W1 XYZ"),
Optional.of("01234 567890"),
Optional.of(Sex.MALE)
);
@theboreddev
theboreddev / constructorWithOptional.java
Created June 9, 2020 16:51
constructorWithOptional
final Customer customer = new Customer(
"John",
"Smith",
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty()
);
import java.util.Optional;
public class Customer {
private final String firstName;
private final String surname;
private final Integer age;
private final String address;
private final String phoneNumber;
private final Sex sex;
final Customer customer = Customer.builderOf("John", "Smith")
.withAge(30)
.build();
System.out.println(customer.getAddress().orElse("No address present"));
@Test
public void convert_shouldReturnI() {
final String romanNumeral = RomanNumerals.convert(1);
assertThat(romanNumeral, is("I"));
}
@Test
public void convert_shouldReturnI() {
final String romanNumeral = RomanNumerals.convert(1);
assertThat(romanNumeral, is("I"));
}
public class RomanNumerals {
public static String convert(int number) {
return "";
}
}