Skip to content

Commit

Permalink
Update tests to Junit 5.5.2 (#340)
Browse files Browse the repository at this point in the history
* Update imports in most of the files

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>

* Add runner to pom, fix imports, collect frequently used jsonb instances

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>

* Merge more jsonb instances, some whitespace refactorings

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>

* Remove some more whitespace, remove commented out jsonb field

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>

* Fix 2 failing tests

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>

* Rebase on master, update test

Signed-off-by: Gyúróczki Gergő <gergonoorbi@gmail.com>
  • Loading branch information
Degubi authored and aguibert committed Oct 14, 2019
1 parent 0c18f1f commit 9e611d1
Show file tree
Hide file tree
Showing 73 changed files with 1,059 additions and 1,509 deletions.
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,17 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -552,8 +558,12 @@
<artifactId>weld-se</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
</dependencies>

Expand Down
14 changes: 5 additions & 9 deletions src/test/java/PackagelessClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,33 @@
* Contributors:
* Ehsan Zaery Moghaddam (zaerymoghaddam@gmail.com) - initial implementation
******************************************************************************/
import org.junit.Test;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.eclipse.yasson.Jsonbs.*;

/**
* Tests the serialization/deserialization of a class that has no package.
*
* @author Ehsan Zaery Moghaddam (zaerymoghaddam@gmail.com)
*/
public class PackagelessClassTest {
private Jsonb jsonb = JsonbBuilder.create();

@Test
public void testSerialization() throws Exception {
PackagelessModel packagelessClass = new PackagelessModel(12, "Hello World!");

String expected = "{\"intValue\":12,\"stringValue\":\"Hello World!\"}";
assertEquals(expected, jsonb.toJson(packagelessClass));
assertEquals(expected, defaultJsonb.toJson(packagelessClass));
}

@Test
public void testDeSerialization() throws Exception {
PackagelessModel packagelessClass = new PackagelessModel(12, "Hello World!");

String input = "{\"intValue\":12,\"stringValue\":\"Hello World!\"}";
PackagelessModel packagelessModel = jsonb.fromJson(input, PackagelessModel.class);
PackagelessModel packagelessModel = defaultJsonb.fromJson(input, PackagelessModel.class);
assertEquals(packagelessModel.getIntValue(), 12);
assertEquals(packagelessModel.getStringValue(), "Hello World!");
}

}
4 changes: 1 addition & 3 deletions src/test/java/org/eclipse/yasson/Assertions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.eclipse.yasson;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -61,7 +61,5 @@ public static void shouldFail(Supplier<?> operation, Class<? extends Throwable>
fail("Expected to get an exception of " + expectedType + " but instead was " + t.getClass());
}
}

}

}
38 changes: 14 additions & 24 deletions src/test/java/org/eclipse/yasson/DefaultGetterInInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,23 @@
******************************************************************************/
package org.eclipse.yasson;

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.eclipse.yasson.Jsonbs.*;

import org.eclipse.yasson.internal.JsonbContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.json.bind.annotation.JsonbProperty;
import javax.json.spi.JsonProvider;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

/**
*
* @author Maxence Laurent
*/
public class DefaultGetterInInterface {

private Jsonb jsonb;

@Before
public void before() {
jsonb = JsonbBuilder.create();
}

public static interface Defaulted {

default public String getGetterA() {
Expand All @@ -52,8 +42,8 @@ public static class PojoWithDefault implements Defaulted {
@Test
public void testWithDefault() {
PojoWithDefault pojo = new PojoWithDefault();
String result = jsonb.toJson(pojo);
Assert.assertEquals("{\"getterA\":\"valueA\"}", result);
String result = defaultJsonb.toJson(pojo);
assertEquals("{\"getterA\":\"valueA\"}", result);
}

public static interface WithGetterI {
Expand Down Expand Up @@ -144,16 +134,16 @@ public void testWithInheritedAndDefault() throws NoSuchMethodException {
assertEquals(PojoWithDefaultImplementation.class.getMethod("getGetterI"), pojoTwoDefault);

// assert serialized json is correct, including property name as specified by JsonbProperty annotations
this.assertJson(new Pojo(), "implementation");
this.assertJson(new PojoNoAnnotation(), "withGetterI");
this.assertJson(new PojoWithDefaultOnly(), "default");
this.assertJson(new PojoWithDefaultSuperImplementation(), "implementation");
this.assertJson(new PojoWithDefaultImplementation(), "defaultImplementation");
this.assertJson(new PojoGetterDefaultedTwice(), "defaultImplementation");
assertJson(new Pojo(), "implementation");
assertJson(new PojoNoAnnotation(), "withGetterI");
assertJson(new PojoWithDefaultOnly(), "default");
assertJson(new PojoWithDefaultSuperImplementation(), "implementation");
assertJson(new PojoWithDefaultImplementation(), "defaultImplementation");
assertJson(new PojoGetterDefaultedTwice(), "defaultImplementation");
}

private void assertJson(WithGetterI pojo, String expected){
private static void assertJson(WithGetterI pojo, String expected){
assertEquals(expected, pojo.getGetterI());
assertEquals("{\"" + expected + "\":\"" + pojo.getGetterI() + "\"}", jsonb.toJson(pojo));
assertEquals("{\"" + expected + "\":\"" + pojo.getGetterI() + "\"}", defaultJsonb.toJson(pojo));
}
}
24 changes: 12 additions & 12 deletions src/test/java/org/eclipse/yasson/FieldAccessStrategyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* Roman Grigoriadi
******************************************************************************/package org.eclipse.yasson;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
Expand Down Expand Up @@ -62,11 +62,11 @@ public void testPrivateFields() {

String expected = "{\"strField\":\"pojo string\"}";

Assert.assertEquals(expected, jsonb.toJson(pojo));
assertEquals(expected, jsonb.toJson(pojo));
PrivateFields result = jsonb.fromJson(expected, PrivateFields.class);
Assert.assertEquals(false, result.getterCalled);
Assert.assertEquals(false, result.setterCalled);
Assert.assertEquals("pojo string", result.strField);
assertEquals(false, result.getterCalled);
assertEquals(false, result.setterCalled);
assertEquals("pojo string", result.strField);
}


Expand All @@ -79,9 +79,9 @@ public void testHidePublicFields() {

String expected = "{}";

Assert.assertEquals(expected, jsonb.toJson(pojo));
assertEquals(expected, jsonb.toJson(pojo));
PublicFields result = jsonb.fromJson("{\"strField\":\"pojo string\"}", PublicFields.class);
Assert.assertEquals(null, result.strField);
assertEquals(null, result.strField);
}

/**
Expand All @@ -96,13 +96,13 @@ public void testCustomVisibityStrategy() {
simpleContainer.setStringInstance("Test String");
simpleContainer.setIntegerInstance(10);
simpleContainer.setFloatInstance(10.0f);
Assert.assertEquals(json, jsonb.toJson(simpleContainer));
assertEquals(json, jsonb.toJson(simpleContainer));


SimpleContainer result = jsonb.fromJson("{ \"stringInstance\" : \"Test String\", \"floatInstance\" : 1.0, \"integerInstance\" : 1 }", SimpleContainer.class);
Assert.assertEquals("Test String", result.stringInstance);
Assert.assertNull(result.integerInstance);
Assert.assertNull(result.floatInstance);
assertEquals("Test String", result.stringInstance);
assertNull(result.integerInstance);
assertNull(result.floatInstance);
}

public class CustomVisibilityStrategy implements PropertyVisibilityStrategy {
Expand Down
17 changes: 6 additions & 11 deletions src/test/java/org/eclipse/yasson/JavaxNamingExcludedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
******************************************************************************/
package org.eclipse.yasson;

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.eclipse.yasson.Jsonbs.*;

import org.eclipse.yasson.internal.cdi.NonCdiAdapter;
import org.eclipse.yasson.internal.components.JsonbComponentInstanceCreatorFactory;
import org.junit.Assert;
import org.junit.Test;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.annotation.JsonbTypeAdapter;

import static org.junit.Assert.assertEquals;

/**
* Requires --limit-modules java.base,java.logging,java.sql (to exclude java.naming) to work.
* See pom.xml surefire plugin configuration.
Expand All @@ -30,16 +28,14 @@ public class JavaxNamingExcludedTest {
public void testNoJavaxNamingModule() {
try {
Class.forName(JsonbComponentInstanceCreatorFactory.INITIAL_CONTEXT_CLASS);
Assert.fail("Class [" + JsonbComponentInstanceCreatorFactory.INITIAL_CONTEXT_CLASS
fail("Class [" + JsonbComponentInstanceCreatorFactory.INITIAL_CONTEXT_CLASS
+ "] should not be available for this test.");
} catch (ClassNotFoundException e) {
//OK, java.naming is not observable
}

Jsonb jsonb = JsonbBuilder.create();
final String result = jsonb.toJson(new AdaptedPojo());
final String result = defaultJsonb.toJson(new AdaptedPojo());
assertEquals("{\"adaptedValue1\":1111,\"adaptedValue2\":1001,\"adaptedValue3\":1010}", result);

}

public static final class AdaptedPojo {
Expand All @@ -51,6 +47,5 @@ public static final class AdaptedPojo {

@JsonbTypeAdapter(NonCdiAdapter.class)
public String adaptedValue3 = "1010";

}
}
13 changes: 13 additions & 0 deletions src/test/java/org/eclipse/yasson/Jsonbs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.yasson;

import javax.json.bind.*;
import org.eclipse.yasson.internal.*;

public class Jsonbs {
public static final Jsonb defaultJsonb = JsonbBuilder.create();
public static final Jsonb bindingJsonb = new JsonBindingBuilder().build();
public static final Jsonb formattingJsonb = JsonbBuilder.create(new JsonbConfig().withFormatting(Boolean.TRUE));
public static final Jsonb nullableJsonb = JsonbBuilder.create(new JsonbConfig().withNullValues(Boolean.TRUE));
public static final YassonJsonb yassonJsonb = (YassonJsonb) JsonbBuilder.create();
public static final YassonJsonb bindingYassonJsonb = (YassonJsonb) new JsonBindingProvider().create().build();
}
45 changes: 19 additions & 26 deletions src/test/java/org/eclipse/yasson/SimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,40 @@
******************************************************************************/
package org.eclipse.yasson;

import org.eclipse.yasson.internal.JsonBindingBuilder;
import org.junit.Test;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.eclipse.yasson.Jsonbs.*;

/**
* @author Roman Grigoriadi
*/
public class SimpleTest {

public static class StringWrapper {
public String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}


Jsonb jsonb = JsonbBuilder.create();

@Test
public void testSimpleSerialize() {
Jsonb jsonb = (new JsonBindingBuilder()).build();
final StringWrapper wrapper = new StringWrapper();
wrapper.setValue("abc");
jsonb.toJson(wrapper);
final String val = jsonb.toJson(wrapper);
bindingJsonb.toJson(wrapper);
final String val = bindingJsonb.toJson(wrapper);
assertEquals("{\"value\":\"abc\"}", val);
}

@Test
public void testSimpleDeserializer() {
final StringWrapper stringWrapper = jsonb.fromJson("{\"value\":\"abc\"}", StringWrapper.class);
final StringWrapper stringWrapper = defaultJsonb.fromJson("{\"value\":\"abc\"}", StringWrapper.class);
assertEquals("abc", stringWrapper.getValue());
}


public static class StringWrapper {
public String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/eclipse/yasson/YassonPropertiesTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.eclipse.yasson;

import org.junit.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

import static org.eclipse.yasson.YassonProperties.FAIL_ON_UNKNOWN_PROPERTIES;
import static org.eclipse.yasson.YassonProperties.NULL_ROOT_SERIALIZER;
import static org.eclipse.yasson.YassonProperties.USER_TYPE_MAPPING;
import static org.eclipse.yasson.YassonProperties.ZERO_TIME_PARSE_DEFAULTING;
import static org.junit.Assert.assertEquals;

/**
* Tests that the names of configuration fields in {@link YassonProperties} do not change.
Expand Down

0 comments on commit 9e611d1

Please sign in to comment.