Remove explicit type as a constructor parameter
This rolls back the change made for 0.3.0, reverting the API for TypeAlias
This commit is contained in:
parent
f49df2d895
commit
2f16ab6714
2 changed files with 16 additions and 22 deletions
|
@ -38,20 +38,13 @@ public abstract class TypeAlias<T> {
|
||||||
*/
|
*/
|
||||||
private final T value;
|
private final T value;
|
||||||
|
|
||||||
private final Class<? super T> type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param value the value
|
* @param value the value
|
||||||
* @param type the type of the value
|
|
||||||
*/
|
*/
|
||||||
protected TypeAlias(
|
protected TypeAlias(final T value) {
|
||||||
final T value,
|
|
||||||
final Class<? super T> type
|
|
||||||
) {
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
public class TypeAliasTest {
|
public class TypeAliasTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateATypeAliasAndGetTheValue() throws Exception {
|
public void shouldCreateATypeAliasAndGetTheValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
//when
|
//when
|
||||||
|
@ -19,25 +19,25 @@ public class TypeAliasTest {
|
||||||
assertThat(typeAlias.<Boolean>map(value::equals)).isTrue();
|
assertThat(typeAlias.<Boolean>map(value::equals)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TypeAlias<String> givenTypeAlias(final String value) {
|
||||||
|
return new TypeAlias<String>(value) {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateATypeAliasWithNestedGenericTypes() {
|
public void shouldCreateATypeAliasWithNestedGenericTypes() {
|
||||||
//given
|
//given
|
||||||
final Iterable<String> iterable = Collections.emptyList();
|
final Iterable<String> iterable = Collections.emptyList();
|
||||||
//when
|
//when
|
||||||
final TypeAlias<Iterable<String>> typeAlias =
|
final TypeAlias<Iterable<String>> typeAlias =
|
||||||
new TypeAlias<Iterable<String>>(iterable, Iterable.class) {
|
new TypeAlias<Iterable<String>>(iterable) {
|
||||||
};
|
};
|
||||||
//then
|
//then
|
||||||
assertThat(typeAlias.<Boolean>map(iterable::equals)).isTrue();
|
assertThat(typeAlias.<Boolean>map(iterable::equals)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeAlias<String> givenTypeAlias(final String value) {
|
|
||||||
return new TypeAlias<String>(value, String.class) {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateAnAliasedTypeAndGetTheValue() throws Exception {
|
public void shouldCreateAnAliasedTypeAndGetTheValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
//when
|
//when
|
||||||
|
@ -50,13 +50,14 @@ public class TypeAliasTest {
|
||||||
public void shouldNotBeEqualWhenValueTypesAreDifferent() {
|
public void shouldNotBeEqualWhenValueTypesAreDifferent() {
|
||||||
//given
|
//given
|
||||||
final TypeAlias<String> stringTypeAlias = givenTypeAlias("1");
|
final TypeAlias<String> stringTypeAlias = givenTypeAlias("1");
|
||||||
final TypeAlias<Integer> integerTypeAlias = new TypeAlias<Integer>(1, Integer.class){};
|
final TypeAlias<Integer> integerTypeAlias = new TypeAlias<Integer>(1) {
|
||||||
|
};
|
||||||
//then
|
//then
|
||||||
assertThat(stringTypeAlias).isNotEqualTo(integerTypeAlias);
|
assertThat(stringTypeAlias).isNotEqualTo(integerTypeAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeEqualWhenValuesAreTheSame() throws Exception {
|
public void shouldBeEqualWhenValuesAreTheSame() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias1 = AnAlias.of(value);
|
final AnAlias anAlias1 = AnAlias.of(value);
|
||||||
|
@ -66,7 +67,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeEqualToUnAliasedValue() throws Exception {
|
public void shouldBeEqualToUnAliasedValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias = AnAlias.of(value);
|
final AnAlias anAlias = AnAlias.of(value);
|
||||||
|
@ -75,7 +76,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveHashCodeOfValue() throws Exception {
|
public void shouldHaveHashCodeOfValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias = AnAlias.of(value);
|
final AnAlias anAlias = AnAlias.of(value);
|
||||||
|
@ -84,7 +85,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveSameToStringAsAliasedType() throws Exception {
|
public void shouldHaveSameToStringAsAliasedType() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
//when
|
//when
|
||||||
|
@ -112,7 +113,7 @@ public class TypeAliasTest {
|
||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
protected AnAlias(final String value) {
|
protected AnAlias(final String value) {
|
||||||
super(value, String.class);
|
super(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static AnAlias of(final String value) {
|
protected static AnAlias of(final String value) {
|
||||||
|
|
Loading…
Reference in a new issue