Git Product home page Git Product logo

ebean-mocker's Introduction

ebean mocker

Ability to set a Mockito type mock Database as the 'default' Database

ebean-mocker's People

Contributors

dependabot[bot] avatar johnson0125 avatar koendg avatar npraml avatar rbygrave avatar rob-bygrave avatar rpraml avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebean-mocker's Issues

Add WrappingEbeanServer

This wraps an EbeanServer so that you can create a test double that just overwrites some methods but otherwise calls through to the underlying delegate EbeanServer.

Allow WithStaticFinder to take any type (for test double replacement of static Finder)

So here TDCustFinder can be anything. Currently there is a restriction on the type of Finder but that is not ideal as there is Model.Finder and Finder now etc.

    WithStaticFinder with = WithStaticFinder.use(Customer.class, new TDCustFinder());
    try {

      Customer jim = Customer.find.byName("jim");

    } finally {
      with.restoreOriginal();
    }

Similarly we want to do (with any TDCustFinder)

    DelegateEbeanServer server = new DelegateEbeanServer();
    server.withFinder(Customer.class).as(new TDCustFinder());

    // make TDCustFinder the finder for Customer
    server.beforeRun();
    try {

      // run our test code ... that will use TDCustFinder 
      Customer jim = Customer.find.byName("jim");

    } finally {
      // restore the original finder implementation
      server.afterRun();
    }

Does it work with Play 2.5 ?

I am trying to do the following in the tests

    mockServer = mock(EbeanServer.class, withSettings().verboseLogging());
    when(mockServer.getName()).thenReturn("default");
    when(mockServer.toString()).thenReturn("Wazza");
    mockiEbean = MockiEbean.start(mockServer);

and when i try to do a Ebean.getDefaultServer().toString() , it returns com.avaje.ebeaninternal.server.core.DefaultServer@405192e4 from the play controller, but within test it returns"Wazza"as desired .

How can i get this running ?

Update to support ebean version 7.2.1 API

in DelegateEbeanServer class is not implement method docStore method define in EbeanServer interface.

other quest: this project is step by step follow ebean with newest version?

ebean-mock java17 21

in WithStaticFinder Line 46

  public WithStaticFinder<T> as(Object testDouble) throws FinderFieldNotFoundException {
    try {
      this.testDouble = testDouble;
      this.field = findField();
      this.field.setAccessible(true);
      try {
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        /**
         * If the project using this library has a SecurityManager set up, permission may be denied.
         * Therefor, running this as a privileged action.
         */
        AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
          modifiersField.setAccessible(true);
          return null;
        });
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
      } catch (NoSuchFieldException e) {
        // this fails with Java 17
        throw new RuntimeException("Unable to turn off final field flag for " + field, e);
      }

      this.original = field.get(null);
      return this;

    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }

do we have any plan to update this for jdk17 or 21๏ผŸ

MockiEbean with ebean13

Hello @rbygrave ,

we are using now MockiEbean with ebean13 and we get a NoSuchMethodError for getName() in MockiEbean, in the method restoreOriginal() at line 201.
It should be original.name(), the same for line 206.

Can you please fix it?

Kind regards,
Noemi

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.