Skip to content

Commit

Permalink
[eclipse-ee4j#627]Created default constructors, so we would have fewe…
Browse files Browse the repository at this point in the history
…r warnings from module system

Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Nov 8, 2023
1 parent fe4afe0 commit a2966bb
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/eclipse/yasson/FieldAccessStrategy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -28,6 +28,10 @@
* when SecurityManager is turned on.</p>
*/
public class FieldAccessStrategy implements PropertyVisibilityStrategy {

FieldAccessStrategy() {
}

@Override
public boolean isVisible(Field field) {
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/eclipse/yasson/JsonBindingProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -22,6 +22,9 @@
*/
public class JsonBindingProvider extends JsonbProvider {

public JsonBindingProvider() {
}

@Override
public JsonbBuilder create() {
return new JsonBindingBuilder();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/eclipse/yasson/YassonConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 IBM and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 IBM and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -21,6 +21,9 @@
* Custom properties for configuring Yasson outside of the specification {@link jakarta.json.bind.JsonbConfig} scope.
*/
public class YassonConfig extends JsonbConfig {

public YassonConfig() {
}

/**
* @see #withFailOnUnknownProperties(boolean)
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/org/eclipse/yasson/Assertions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -20,6 +20,9 @@
import jakarta.json.bind.JsonbException;

public class Assertions {

private Assertions() {
}

/**
* Asserts that the given operation will fail with a JsonbException
Expand Down Expand Up @@ -58,13 +61,13 @@ public static void shouldFail(Supplier<?> operation, Class<? extends Throwable>
operation.get();
fail("The operation should have failed with a " + expectedType.getCanonicalName() + " but it succeeded.");
} catch (Throwable t) {
String fullErrorMessage = "";
StringBuilder fullErrorMessage = new StringBuilder();
for (Throwable current = t; current != null && current.getCause() != current; current = current.getCause()) {
fullErrorMessage += current.getClass().getCanonicalName() + ": ";
fullErrorMessage += current.getMessage() + "\n";
fullErrorMessage.append(current.getClass().getCanonicalName()).append(": ");
fullErrorMessage.append(current.getMessage()).append("\n");
}
if (expectedType.isAssignableFrom(t.getClass())) {
if (!checkExceptionMessage.apply(fullErrorMessage)) {
if (!checkExceptionMessage.apply(fullErrorMessage.toString())) {
t.printStackTrace();
fail("Exception did not contain the proper content: " + fullErrorMessage);
}
Expand Down
32 changes: 26 additions & 6 deletions src/test/java/org/eclipse/yasson/DefaultGetterInInterface.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -29,14 +29,19 @@
*/
public class DefaultGetterInInterface {

public static interface Defaulted {
private DefaultGetterInInterface() {
}

public interface Defaulted {

default public String getGetterA() {
default String getGetterA() {
return "valueA";
}
}

public static class PojoWithDefault implements Defaulted {
protected PojoWithDefault() {
}
}

@Test
Expand All @@ -46,13 +51,13 @@ public void testWithDefault() {
assertEquals("{\"getterA\":\"valueA\"}", result);
}

public static interface WithGetterI {
public interface WithGetterI {

@JsonbProperty("withGetterI")
String getGetterI();
}

public static interface WithDefaultGetterI extends WithGetterI {
public interface WithDefaultGetterI extends WithGetterI {

@Override
@JsonbProperty("default")
Expand All @@ -61,7 +66,7 @@ default String getGetterI() {
}
}

public static interface OtherWithDefaultGetterI extends WithGetterI {
public interface OtherWithDefaultGetterI extends WithGetterI {

@Override
@JsonbProperty("otherDefault")
Expand All @@ -72,6 +77,9 @@ default String getGetterI() {

public static class Pojo implements WithGetterI {

protected Pojo() {
}

@Override
@JsonbProperty("implementation")
public String getGetterI() {
Expand All @@ -82,17 +90,25 @@ public String getGetterI() {

public static class PojoNoAnnotation implements WithGetterI {

protected PojoNoAnnotation() {
}

@Override
public String getGetterI() {
return "withGetterI";
}
}

public static class PojoWithDefaultSuperImplementation extends Pojo implements WithDefaultGetterI {
protected PojoWithDefaultSuperImplementation() {
}
}

public static class PojoWithDefaultImplementation implements WithDefaultGetterI {

protected PojoWithDefaultImplementation() {
}

@Override
@JsonbProperty("defaultImplementation")
public String getGetterI() {
Expand All @@ -102,9 +118,13 @@ public String getGetterI() {
}

public static class PojoWithDefaultOnly implements WithDefaultGetterI {
protected PojoWithDefaultOnly() {
}
}

public static class PojoGetterDefaultedTwice extends PojoWithDefaultImplementation implements OtherWithDefaultGetterI {
protected PojoGetterDefaultedTwice() {
}
}

@Test
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/eclipse/yasson/FieldAccessStrategyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

public class FieldAccessStrategyTest {

private FieldAccessStrategyTest() {
}

public static class PrivateFields {
private String strField;
@JsonbTransient
Expand All @@ -49,6 +52,10 @@ public void setStrField(String strField) {
}

public static class PublicFields {

protected PublicFields() {
}

public String strField;
}

Expand Down Expand Up @@ -109,6 +116,9 @@ public void testCustomVisibityStrategy() {
}

public static class CustomVisibilityStrategy implements PropertyVisibilityStrategy {
public CustomVisibilityStrategy() {
}

@Override
public boolean isVisible(Field field) {
return field.getName().equals("stringInstance");
Expand All @@ -121,6 +131,9 @@ public boolean isVisible(Method method) {
}

public static class SimpleContainer {
protected SimpleContainer() {
}

private String stringInstance;
private Integer integerInstance;
private Float floatInstance;
Expand Down Expand Up @@ -153,6 +166,9 @@ public void setFloatInstance(float floatInstance) {

private static final class NoAccessStrategy implements PropertyVisibilityStrategy {

public NoAccessStrategy() {
}

@Override
public boolean isVisible(Field field) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/eclipse/yasson/Issue454Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

public class Issue454Test {

private Issue454Test() {
}

@Test
public void test() {
final String EXPECTED = "{\"field2\":\"bbb\"}";
Expand Down Expand Up @@ -56,13 +59,21 @@ public String getField2() {
}

public static abstract class TheClass {

private TheClass() {
}

@JsonbTransient
public abstract String getField1();

public abstract String getField2();
}

public static class TheClass2 extends TheClass {

private TheClass2() {
}

@Override
public String getField1() {
return "aaa";
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/eclipse/yasson/Issue456Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

public class Issue456Test {

private Issue456Test() {
}

@Test
public void dontInvokeToString() {
try {
Expand All @@ -33,6 +36,9 @@ public void dontInvokeToString() {

public static class Example {

protected Example() {
}

public String getProperty() {
throw new RuntimeException("some error");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -27,6 +27,9 @@
*/
public class JavaxNamingExcludedTest {

private JavaxNamingExcludedTest() {
}

@Test
public void testNoJavaxNamingModule() {
try {
Expand All @@ -42,6 +45,10 @@ public void testNoJavaxNamingModule() {
}

public static final class AdaptedPojo {

private AdaptedPojo() {
}

@JsonbTypeAdapter(NonCdiAdapter.class)
public String adaptedValue1 = "1111";

Expand Down
8 changes: 7 additions & 1 deletion src/test/java/org/eclipse/yasson/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -23,6 +23,9 @@
*/
public class SimpleTest {

private SimpleTest() {
}

@Test
public void testSimpleSerialize() {
final StringWrapper wrapper = new StringWrapper();
Expand All @@ -39,6 +42,9 @@ public void testSimpleDeserializer() {

public static class StringWrapper {

protected StringWrapper() {
}

public String value;

public String getValue() {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/eclipse/yasson/TestTypeToken.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,6 +19,10 @@
* @author Roman Grigoriadi
*/
public abstract class TestTypeToken<T> {

protected TestTypeToken() {
}

public Type getType() {
return ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/eclipse/yasson/YassonConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,16 +14,15 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;

import org.junit.jupiter.api.Test;

/**
* Tests that the names of configuration fields in {@link YassonConfig} do not change.
*/
public class YassonConfigTest {

private YassonConfigTest() {}

@SuppressWarnings("deprecation")
@Test
public void testFailOnUnknownPropertiesUnchanged() {
Expand Down

0 comments on commit a2966bb

Please sign in to comment.