|
| 1 | +package graphql |
| 2 | + |
| 3 | +import graphql.language.SourceLocation |
| 4 | +import graphql.validation.ValidationError |
| 5 | +import graphql.validation.ValidationErrorType |
| 6 | +import spock.lang.Specification |
| 7 | + |
| 8 | + |
| 9 | +@SuppressWarnings("ChangeToOperator") |
| 10 | +class ErrorsTest extends Specification { |
| 11 | + |
| 12 | + def src(int line, int col) { |
| 13 | + new SourceLocation(line,col) |
| 14 | + } |
| 15 | + |
| 16 | + |
| 17 | + private static void commonAssert(GraphQLError same1, GraphQLError same2, GraphQLError different1) { |
| 18 | + same1.equals(same2) |
| 19 | + same1.hashCode() == same2.hashCode() |
| 20 | + |
| 21 | + same2.equals(same1) |
| 22 | + |
| 23 | + // we should equal ourselves |
| 24 | + same1.equals(same1) |
| 25 | + |
| 26 | + !same1.equals(different1) |
| 27 | + same1.hashCode() != different1.hashCode() |
| 28 | + } |
| 29 | + |
| 30 | + def "InvalidSyntaxError equals and hashcode works"() { |
| 31 | + expect: |
| 32 | + |
| 33 | + def same1 = new InvalidSyntaxError(src(15,34)) |
| 34 | + def same2 = new InvalidSyntaxError(src(15,34)) |
| 35 | + def different1 = new InvalidSyntaxError([src(24,100), src(15,34)]) |
| 36 | + |
| 37 | + commonAssert(same1, same2, different1) |
| 38 | + } |
| 39 | + |
| 40 | + def "ValidationError equals and hashcode works"() { |
| 41 | + expect: |
| 42 | + |
| 43 | + def same1 = new ValidationError(ValidationErrorType.BadValueForDefaultArg,[src(15,34),src(23,567)],"bad ju ju") |
| 44 | + def same2 = new ValidationError(ValidationErrorType.BadValueForDefaultArg,[src(15,34),src(23,567)],"bad ju ju") |
| 45 | + def different1 = new ValidationError(ValidationErrorType.FieldsConflict,[src(15,34),src(23,567)],"bad ju ju") |
| 46 | + |
| 47 | + commonAssert(same1, same2, different1) |
| 48 | + } |
| 49 | + |
| 50 | + def "ExceptionWhileDataFetching equals and hashcode works"() { |
| 51 | + expect: |
| 52 | + |
| 53 | + def same1 = new ExceptionWhileDataFetching(new RuntimeException("bad ju ju")) |
| 54 | + def same2 = new ExceptionWhileDataFetching(new RuntimeException("bad ju ju")) |
| 55 | + def different1 = new ExceptionWhileDataFetching(new RuntimeException("unexpected ju ju")) |
| 56 | + |
| 57 | + commonAssert(same1, same2, different1) |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +} |
0 commit comments