Search code examples
javadeprecatedpact

The method getPactFile() from the type ConsumerInfo is deprecated


I've got the following two lines from this example: https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider

consumer.setPactFile(new File("target/pacts/ping_client-ping_service.json"));
testConsumerPact = (Pact) PactReader.loadPact(consumer.getPactFile());

They result in the message:

The method getPactFile() from the type ConsumerInfo is deprecated

What to use instead?

Thanks for your help in advance.


Solution

  • A look into sourcecode revealed the answer:

    /**
       * Sets the Pact File for the consumer
       * @param file Pact file, either as a string or a PactSource
       * @deprecated Use setPactSource instead
       */
      @Deprecated
      void setPactFile(def file) {
        if (file instanceof PactSource) {
          pactSource = file
        } else {
          pactSource = new FileSource(file as File)
        }
      }
    
      /**
       * Returns the Pact file for the consumer
       * @deprecated Use getPactSource instead
       */
      @Deprecated
      def getPactFile() {
        pactSource
      }