Giter Club home page Giter Club logo

red-and-blue's Introduction

red-and-blue-factory-extension

JUnit 5 extension for easy injection of Red and Blue objects

red-and-blue's People

Contributors

renovate[bot] avatar neboskreb avatar

Stargazers

 avatar

Watchers

 avatar

red-and-blue's Issues

Create independent copies for injection

Create independent copies for injection

Curerntly, the same instance is injected at all injection points. I.e., this fails:

@Test
private foo(@BlueInstance one, @BlueInstance another) {
    assertNotSame(one, another);
}

This can be dangerous if the test modifies the content of the injected instance, as this change will be visible through all other injected blue instances, thus violating the expectations in the other (concurrently executed) tests or later in the same test.

Suggested solution:

Before injection, create a deep copy of the "etalon instance", and inject that copy instead.

Once the objective achieved, this should pass (pseudocode):

@Test
private foo(@BlueInstance one, @BlueInstance another) {
    assertDeepNotSame(one, another);
    assertDeepReflectionEqueals(one, another);
}

Default - deep or shallow?

Deep copy is best for the test isolation but comes at performance price. The latter should be profiled, and if found insignificant then the default should be set to deep copy.

A way of configuration must be provided to control this behavior. For example, class-level annotation @RedAndBlueSettings with field createCopies would work nicely.

Confusing error message when a prefab is needed

Confusing error message when a prefab is needed

When object factory fails to construct a prefab automatically (e.g. because the type is abstract or non-instantiable), an exception is thrown which explains very little about the problem and difficult to enterpret.

Receiver class nl.jqno.equalsverifier.internal.reflection.PublicKey$$DynamicSubclass$41294f8$ does not define or inherit an implementation of the resolved method 'abstract byte[] getEncoded()' of interface java.security.Key.
java.lang.AbstractMethodError: Receiver class nl.jqno.equalsverifier.internal.reflection.PublicKey$$DynamicSubclass$41294f8$ does not define or inherit an implementation of the resolved method 'abstract byte[] getEncoded()' of interface java.security.Key.
	at core.security.PublicKeyEncoding.encodeX509(PublicKeyEncoding.java:47)
	at core.state.EncryptionKeysMapper.encodePublicKey(EncryptionKeysMapper.java:34)
	at core.state.EncryptionKeysMapperImpl.encryptionKeysToPublicKeyEntity(EncryptionKeysMapperImpl.java:52)
	at core.state.EncryptionKeysMapperImpl.toEntity(EncryptionKeysMapperImpl.java:25)
	at core.state.EndpointAppKeysMapperImpl.toEntity(EndpointAppKeysMapperImpl.java:29)
	at state.EndpointAppKeysMapperTest.testTransitive(EndpointAppKeysMapperTest.java:33)

Such exception should be wrapped into a higher-level exception explaining the problem and possible solution (i.e., Consider introducing a prefab for PublicKey)

Minimal reproducible example

public class EndpointAppKeys {
  private CipherSuite cipherSuite;
  private EncryptionKeys clientKeys;
}

public class EncryptionKeys {
  private PublicKey publicKey;  // <-- PublicKey is interface. It declares but never defines `public byte[] getEncoded()`, hence the failure to instantiate the mock
}

@ExtendWith(RedAndBlueExtension.class)
public class EndpointAppKeysMapperTest {

    @Test
    void testTransitive(@RedInstance EndpointAppKeys red, @BlueInstance EndpointAppKeys blue) {
       ...
    }
}

Investigate failing to instantiate a `JsonNode`

Abnormal behavior was reported by @nextincrement

The issue I encountered is that. when defining an instance of JsonNode as a prefab value, some error is raised because the abstract class JsonNode does not meet some requirements - while it's concrete implementation (so, not the declared class but the actuall class) should be fine. I know this because, when using equals-verifier, I can succesfully define two prefab values for an instance of JsonNode.
...
However, this [instantiating builders] does unfortunately not apply to the JsonNode as this type is also used in any builder (JsonNode in -> JsonNode out). I think that a very simple minimal test case: creating a red/blue instance for a class using just a JsonNode field (or maby two fields, including a simple string) may reveil the bug. If my recollection is right, it should fail immediately but can't test it right now due to some compiler errors I need to fix first.

Needs investigation

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/gradle-publish.yml
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/wrapper-validation-action f9c9c575b8b21b6485636a91ffecd10e558c62f6
  • gradle/gradle-build-action ac2d340dc04d9e1113182899e983b5400c17cda1
.github/workflows/gradle.yml
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/actions v4.0.0@af1da67850ed9a4cedd57bfd976089dd991e2582
  • mikepenz/action-junit-report v4
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/actions v4.0.0@af1da67850ed9a4cedd57bfd976089dd991e2582
gradle
gradle.properties
settings.gradle
build.gradle
red-and-blue/build.gradle
  • nl.jqno.equalsverifier:equalsverifier 3.16.1
  • org.junit.jupiter:junit-jupiter-api 5.10.3
  • org.junit.jupiter:junit-jupiter-params 5.10.3
  • org.junit.jupiter:junit-jupiter-engine 5.10.3
  • org.junit.jupiter:junit-jupiter-api 5.10.3
  • org.junit.jupiter:junit-jupiter-params 5.10.3
  • org.junit.jupiter:junit-jupiter-engine 5.10.3
  • org.mockito:mockito-core 5.12.0
  • org.mockito:mockito-junit-jupiter 5.12.0
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.9

  • Check this box to trigger a request for Renovate to run again on this repository

Improve recognition of generic prefabs

Improve recognition of generic prefabs

The following example fails with exception "java.lang.IllegalStateException: Missing RED prefab of type null":

public class Entity {
    private final EntityColor color;
}

public class EntityBuilder {
    private Supplier<EntityColor> colorSupplier;

    public Entity build() {
        return new Entity(colorSupplier.get());
    }
}

@ExtendWith(RedAndBlueExtension.class)
public class EndpointConnectionMapperTest {

    @PrefabRed
    private Supplier<EntityColor> prefabRed = () -> new EntityColor("red");
    @PrefabBlue
    private Supplier<EntityColor> prefabBlue = () -> new EntityColor("blue");

    @Test
    void testTransitive(@RedInstance EntityBuilder redBuilder, @BlueInstance EntityBuilder blueBuilder) {
        // GIVEN
        Entity red = redBuilder.build();
        Entity blue = blueBuilder.build();
        ...
    }
}

The exception trace attached as file exception_trace.txt

Change dependency scope to `test`

Currently, at Maven Central it shows up as production dependency:

// https://mvnrepository.com/artifact/io.github.neboskreb/red-and-blue
implementation 'io.github.neboskreb:red-and-blue:1.1.0'

Update the Maven metadata so the scope is shown as test:

// https://mvnrepository.com/artifact/io.github.neboskreb/red-and-blue
testImplementation 'io.github.neboskreb:red-and-blue:1.1.0'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.