Skip to content

Commit

Permalink
Change tests to package scope (#441)
Browse files Browse the repository at this point in the history
* Follow JUnit 5 best practice
* Merge two `FlexiBean` test classes
* Tweak Javadoc of test classes
* Workaround "unlikely-arg-type" warnings
  • Loading branch information
jodastephen authored Dec 3, 2024
1 parent cbb8995 commit a0ba88f
Show file tree
Hide file tree
Showing 56 changed files with 1,193 additions and 1,192 deletions.
4 changes: 1 addition & 3 deletions src/test/java/org/joda/beans/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

/**
* Examples using Person.
*
* @author Stephen Colebourne
*/
public class Examples {

Expand Down Expand Up @@ -56,7 +54,7 @@ public static void main(String[] args) {
System.out.println(p);

// create the bean the hard way - could just do new Address() instead
Address a = (Address) Address.meta().builder().build();
Address a = Address.meta().builder().build();
// set surname using normal method
a.setStreet("Barnsnap Close");
// query using property method
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/org/joda/beans/TestAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
/**
* Test property using Person.
*/
public class TestAddress {
class TestAddress {

private static final int NUM_PROPERTIES = 4;
private static final String STREET = "street";
private static final String CITY = "city";
private static final String NUMBER = "number";

@Test
public void test_bean() {
void test_bean() {
Bean test = new Address();

assertThat(test).isInstanceOf(Address.class);
Expand All @@ -56,14 +56,14 @@ public void test_bean() {
}

@Test
public void test_bean_invalidPropertyName() {
void test_bean_invalidPropertyName() {
Bean test = Address.meta().builder().build();
assertThatExceptionOfType(NoSuchElementException.class)
.isThrownBy(() -> test.property("Rubbish"));
}

@Test
public void test_builder1() {
void test_builder1() {
BeanBuilder<? extends Address> builder = Address.meta().builder();
builder.set("street", "Main Street");
assertThat(builder.get("street")).isEqualTo("Main Street");
Expand All @@ -84,7 +84,7 @@ public void test_builder1() {
}

@Test
public void test_builder2() {
void test_builder2() {
BeanBuilder<? extends Address> builder = Address.meta().builder();
builder.set(Address.meta().street(), "Main Street");
builder.set(Address.meta().number(), 12);
Expand All @@ -98,22 +98,22 @@ public void test_builder2() {
}

@Test
public void test_builder_getInvalidPropertyName() {
void test_builder_getInvalidPropertyName() {
BeanBuilder<? extends Address> builder = Address.meta().builder();
assertThatExceptionOfType(NoSuchElementException.class)
.isThrownBy(() -> builder.get("Rubbish"));
}

@Test
public void test_builder_setInvalidPropertyName() {
void test_builder_setInvalidPropertyName() {
BeanBuilder<? extends Address> builder = Address.meta().builder();
assertThatExceptionOfType(NoSuchElementException.class)
.isThrownBy(() -> builder.set("Rubbish", ""));
}

//-----------------------------------------------------------------------
@Test
public void test_metaBean() {
void test_metaBean() {
MetaBean test = Address.meta();

assertThat(test.beanType()).isEqualTo(Address.class);
Expand Down Expand Up @@ -141,15 +141,15 @@ public void test_metaBean() {
}

@Test
public void test_metaBean_invalidPropertyName() {
void test_metaBean_invalidPropertyName() {
MetaBean test = Address.meta();
assertThatExceptionOfType(NoSuchElementException.class)
.isThrownBy(() -> test.metaProperty("Rubbish"));
}

//-----------------------------------------------------------------------
@Test
public void test_namedPropertyMethod() {
void test_namedPropertyMethod() {
Address address = new Address();
Property<String> test = address.street();

Expand All @@ -167,7 +167,7 @@ public void test_namedPropertyMethod() {

//-----------------------------------------------------------------------
@Test
public void test_property_String() {
void test_property_String() {
Address address = new Address();
Property<String> test = address.property(STREET);

Expand All @@ -185,7 +185,7 @@ public void test_property_String() {

//-----------------------------------------------------------------------
@Test
public void test_namedMetaPropertyMethod() {
void test_namedMetaPropertyMethod() {
Address address = new Address();
MetaProperty<String> test = Address.meta().street();

Expand All @@ -205,7 +205,7 @@ public void test_namedMetaPropertyMethod() {

//-----------------------------------------------------------------------
@Test
public void test_metaProperty_String() {
void test_metaProperty_String() {
Address address = new Address();
MetaProperty<String> test = Address.meta().metaProperty(STREET);

Expand All @@ -225,7 +225,7 @@ public void test_metaProperty_String() {

//-----------------------------------------------------------------------
@Test
public void test_metaProperty_types() {
void test_metaProperty_types() {
MetaProperty<String> test = Address.meta().street();

assertThat(test.metaBean().beanType()).isEqualTo(Address.class);
Expand All @@ -234,7 +234,7 @@ public void test_metaProperty_types() {
}

@Test
public void test_metaProperty_annotations() {
void test_metaProperty_annotations() {
MetaProperty<String> prop = Address.meta().street();
List<Annotation> test = prop.annotations();

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/joda/beans/TestArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
/**
* Test arrays using SimpleName.
*/
public class TestArray {
class TestArray {

@Test
public void test_bean() {
void test_bean() {
SimpleName person1 = new SimpleName();
person1.setForename("Etienne");
person1.setMiddleNames(new String[] {"Yakusa", "Mohito"});
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/org/joda/beans/TestBasicBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.joda.beans.impl.BasicBean;
import org.joda.beans.sample.Address;
import org.joda.beans.sample.CompanyAddress;
import org.joda.beans.sample.Person;
import org.junit.jupiter.api.Test;

/**
* Test BasicBean.
* Test {@link BasicBean}.
*/
public class TestBasicBean {
class TestBasicBean {

@SuppressWarnings("unlikely-arg-type")
@Test
public void test_equals() {
void test_equals() {
Person a1 = new Person();
Person a2 = new Person();
Person b = new Person();
Expand All @@ -46,12 +46,13 @@ public void test_equals() {
assertThat(a1.equals(b)).isFalse();
assertThat(b.equals(a1)).isFalse();

assertThat(b.equals("Weird type")).isFalse();
Object obj = "Weird type";
assertThat(b.equals(obj)).isFalse();
assertThat(b.equals(null)).isFalse();
}

@Test
public void test_hashCode() {
void test_hashCode() {
Person a1 = new Person();
Person a2 = new Person();

Expand All @@ -62,7 +63,7 @@ public void test_hashCode() {
}

@Test
public void test_toString() {
void test_toString() {
Person a = new Person();
a.setForename("Stephen");
a.setSurname("Colebourne");
Expand All @@ -76,7 +77,7 @@ public void test_toString() {

//-----------------------------------------------------------------------
@Test
public void test_property_equals() {
void test_property_equals() {
Address obj1 = new Address();
CompanyAddress obj2 = new CompanyAddress();
Property<String> p1 = obj1.city();
Expand All @@ -89,7 +90,7 @@ public void test_property_equals() {
}

@Test
public void test_property_hashCode() {
void test_property_hashCode() {
Person obj1 = new Person();
Person obj2 = new Person();
Property<String> p1 = obj1.forename();
Expand All @@ -102,7 +103,7 @@ public void test_property_hashCode() {
}

@Test
public void test_property_toString() {
void test_property_toString() {
Person obj1 = new Person();
Property<String> p1 = obj1.forename();

Expand All @@ -113,23 +114,23 @@ public void test_property_toString() {

//-----------------------------------------------------------------------
@Test
public void test_metaProperty_equals() {
void test_metaProperty_equals() {
MetaProperty<String> p1 = Address.meta().city();
MetaProperty<String> p2 = CompanyAddress.meta().city();

assertThat(p1).isEqualTo(p2);
}

@Test
public void test_metaProperty_hashCode() {
void test_metaProperty_hashCode() {
MetaProperty<String> p1 = Person.meta().forename();
MetaProperty<String> p2 = Person.meta().forename();

assertThat(p1.hashCode()).isEqualTo(p2.hashCode());
}

@Test
public void test_metaProperty_toString() {
void test_metaProperty_toString() {
MetaProperty<String> mp1 = Person.meta().forename();

assertThat(mp1).hasToString("Person:forename");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/joda/beans/TestBeanCodeGenException.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.junit.jupiter.api.Test;

/**
* Test exception, message is parsed by plugins.
* Test {@link BeanCodeGenException}, message is parsed by plugins.
*/
public class TestBeanCodeGenException {
class TestBeanCodeGenException {

private static final File FILE = new File(".");

@Test
public void testMessage() {
void testMessage() {
BeanCodeGenException test = new BeanCodeGenException("rubbish", FILE, 123);
assertThat(test.getMessage()).isEqualTo("Error in bean: " + FILE.toString() + ", Line: 123, Message: rubbish");
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/joda/beans/TestBeanIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import com.google.common.collect.ImmutableList;

/**
* Test BeanIterator.
* Test {@link BeanIterator}.
*/
public class TestBeanIterator {
class TestBeanIterator {

@Test
public void test_iteration_noChildren() {
void test_iteration_noChildren() {
ImmEmpty bean = ImmEmpty.builder().build();
Iterator<Bean> it = JodaBeanUtils.beanIterator(bean);
assertThat(it.hasNext()).isTrue();
Expand All @@ -42,7 +42,7 @@ public void test_iteration_noChildren() {
}

@Test
public void test_iteration_nullChild() {
void test_iteration_nullChild() {
Address bean = new Address();
Iterator<Bean> it = JodaBeanUtils.beanIterator(bean);
assertThat(it.hasNext()).isTrue();
Expand All @@ -51,7 +51,7 @@ public void test_iteration_nullChild() {
}

@Test
public void test_iteration_childWithChildren() {
void test_iteration_childWithChildren() {
ImmTreeNode node1 = ImmTreeNode.builder().name("1").build();
ImmTreeNode node2 = ImmTreeNode.builder().name("2").build();
ImmTreeNode root = ImmTreeNode.builder()
Expand All @@ -71,7 +71,7 @@ public void test_iteration_childWithChildren() {
}

@Test
public void test_iteration_childWithChildrenOfChildren() {
void test_iteration_childWithChildrenOfChildren() {
ImmTreeNode node1 = ImmTreeNode.builder().name("1").build();
ImmTreeNode node2 = ImmTreeNode.builder().name("2").build();
ImmTreeNode node3 = ImmTreeNode.builder()
Expand All @@ -97,7 +97,7 @@ public void test_iteration_childWithChildrenOfChildren() {
}

@Test
public void test_iteration_childWithListOfChildren() {
void test_iteration_childWithListOfChildren() {
ImmTreeNode node1a = ImmTreeNode.builder().name("1a").build();
ImmTreeNode node1b = ImmTreeNode.builder().name("1b").build();
ImmTreeNode node1 = ImmTreeNode.builder()
Expand Down Expand Up @@ -141,7 +141,7 @@ public void test_iteration_childWithListOfChildren() {

//-----------------------------------------------------------------------
@Test
public void test_iteration_childWithNoChildren_FlexiBean() {
void test_iteration_childWithNoChildren_FlexiBean() {
FlexiBean bean1 = new FlexiBean();
Iterator<Bean> it = JodaBeanUtils.beanIterator(bean1);
assertThat(it.hasNext()).isTrue();
Expand All @@ -150,7 +150,7 @@ public void test_iteration_childWithNoChildren_FlexiBean() {
}

@Test
public void test_iteration_childWithOneChild_FlexiBean() {
void test_iteration_childWithOneChild_FlexiBean() {
FlexiBean bean1 = new FlexiBean();
FlexiBean bean2 = new FlexiBean();
bean1.set("a", bean2);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/joda/beans/TestClone.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
/**
* Test property using ClonePerson.
*/
public class TestClone {
class TestClone {

@Test
public void test_bean() {
void test_bean() {
ClonePerson base = new ClonePerson();
base.setSurname("Cable");
base.setMiddleNames(new String[] {"A", "B", "C"});
Expand All @@ -60,7 +60,7 @@ public void test_bean() {
}

@Test
public void test_noclone_on_mutable_bean_option() {
void test_noclone_on_mutable_bean_option() {
Class<?> c = NoClone.class;
Method[] noCloneMethods = c.getDeclaredMethods();

Expand Down
Loading

0 comments on commit a0ba88f

Please sign in to comment.