Last active
August 29, 2015 14:05
-
-
Save patrickhuber/c8dbb406ca9fa16c6a55 to your computer and use it in GitHub Desktop.
Java Property Class
This file contains 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
package com.props.tests; | |
import java.util.Date; | |
import com.props.*; | |
public class Person { | |
public final Property<Integer> id = new Property<Integer>(); | |
public final Property<String> firstName = new Property<String>(); | |
public final Property<String> lastName = new Property<String>(); | |
public final Property<Date> dateOfBirth = new Property<Date>(); | |
} |
This file contains 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
package com.props.tests; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
public class PersonFixture { | |
@Test | |
public void testPersonGivenPropertyWhenFirstNameSetThenHasValue() { | |
Person person = new Person(); | |
person.firstName.set("Patrick"); | |
assertEquals("Patrick", person.firstName.get()); | |
} | |
} |
This file contains 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
package com.props; | |
public class Property<T> { | |
private T value; | |
public Property(){ | |
} | |
public Property(T value){ | |
set(value); | |
} | |
public T get() { | |
return value; | |
} | |
public void set(T value) { | |
this.value = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment