Skip to content

Instantly share code, notes, and snippets.

@patrickhuber
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickhuber/c8dbb406ca9fa16c6a55 to your computer and use it in GitHub Desktop.
Save patrickhuber/c8dbb406ca9fa16c6a55 to your computer and use it in GitHub Desktop.
Java Property Class
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>();
}
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());
}
}
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