Coder Social home page Coder Social logo

Comments (10)

mariuszs avatar mariuszs commented on July 30, 2024

We are using AssertJ now, so you can easily write custom assertions for your business exception http://joel-costigliola.github.io/assertj/assertj-core-custom-assertions.html.

Please show your code for catch-exception before 1.4.2.

I take look into Intellij warning...

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

Ok, custom assertion dosent help here. I need to think about this :) Thanks for the report

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

I have only one solution to this problems ->
mariuszs@2b9ff7a

 thenCaughtException()
                .isInstanceOf(IndexOutOfBoundsException.class) //
                .hasMessage("Index: 1, Size: 0") //
                .hasNoCause();

thenCaughtException is using AssertJ api

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

Fixed in #27

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

I leave old behaviour for Java 6 and 7, for Java 8 this is not working, my proposition for java 8:

when(service).doSomething();

then(caughtException((BusinessRuleException.class))
    .isInstanceOfAndGet(BusinessRuleException.class)
    .getCode().isEqualTo(MY_ERROR_CODE);

3f0db06

from catch-exception.

sedubois avatar sedubois commented on July 30, 2024

Is clearly better, but

then(caughtException(BusinessRuleException.class))
.isInstanceOfAndGet(BusinessRuleException.class)

still very much looks like code duplication. isInstanceOfAndGet() should be automatically done inside the then(caughtException()) or similar.

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

You are absolutly right, but I dont know how to do that (for Java8).

http://stackoverflow.com/questions/29499847/ambiguous-method-in-java-8-why

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

You can do something like this

https://github.com/Codearte/catch-exception/blob/2.x/catch-exception/src/test/java/com/googlecode/catchexception/test/apis/BDDCustomCatchExceptionTest.java

from catch-exception.

evilmilo avatar evilmilo commented on July 30, 2024

Can we get a non-generic version of caughtException() added?

At moment the signature is

public static <E extends Exception> E caughtException()

java 8 is now more strict, and requires the caller to define that type. Where method overloading means multiple parameters could match, you now get the ambiguity error.

for most of the assert frameworks, we just want to pass Exception in. so it would be handier if the method signature was just:

public static Exception caughtException()

Which would remove the ambiguity. To avoid breaking existing code, could either add non generic method with different name, or create a new parallel class that doesn't use the generics.

from catch-exception.

mariuszs avatar mariuszs commented on July 30, 2024

Sorry for delay, I have missed your answer,

I have added Exception caughtException() to BDDCatchException

Btw, we can use something like org.assertj.core.api.AssertionsForClassTypes in Java8 with non-generic caughtException().

from catch-exception.

Related Issues (19)

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.