title: Check if a method was called inside another method
body: <p>Is there any way in java to check if a certain method was called inside another method? I am testing a class and the method I am having trouble with plays sound and there is virtually no way of getting the audio file that is played(private attribute inside an inner class) without changing the code. However the way the method plays sounds is it calls a method that plays a single sound (playSadMusic, playHappyMusic, etc). Those methods are in an interface that I have to create a mock object for. I'm a little stuck on how I would exactly go about testing this. Any thoughts? Any other ideas on how I could possibly test this other than check if a certain method was call are welcome.</p>
  
  <p>I am using JMock 2.6.0 and JUnit 4</p>
  
  <p>the audio inteface </p>
  
  <pre><code>public interface StockTickerAudioInterface {
  
      public abstract void playHappyMusic();
  
      public abstract void playSadMusic();
  
      public abstract void playErrorMusic();
  }
  </code></pre>
  
  <p>anther interface I have to create a mock for</p>
  
  <pre><code>public interface StockQuoteGeneratorInterface {
      public abstract StockQuoteInterface getCurrentQuote() throws Exception;
  
      public abstract String getSymbol();
  
      public abstract void setSymbol(String symbol);
  
      public abstract StockQuoteGeneratorInterface createNewInstance(String symbol);
  
  }
  </code></pre>
  
  <p>the class being tested</p>
  
  <pre><code>public class StockQuoteAnalyzer {
      private StockTickerAudioInterface audioPlayer = null;
      private String symbol;
      private StockQuoteGeneratorInterface stockQuoteSource = null;
  
      private StockQuoteInterface lastQuote = null;
      private StockQuoteInterface currentQuote = null;
  
  
      public StockQuoteAnalyzer(String symbol,
          StockQuoteGeneratorInterface stockQuoteSource,
          StockTickerAudioInterface audioPlayer)
          throws InvalidStockSymbolException, NullPointerException,
          StockTickerConnectionError {
          super(); 
  
      // Check the validity of the symbol.
          if (StockTickerListing.getSingleton().isValidTickerSymbol(symbol) == true){
              this.symbol = symbol;
          } else {
          throw new InvalidStockSymbolException("Symbol " + symbol
                  + "not found.");
          }
          if (stockQuoteSource == null) {
               throw new NullPointerException(
                  "The source for stock quotes can not be null");
          }
          this.stockQuoteSource = stockQuoteSource;
          this.audioPlayer = audioPlayer;
      }
      public double getChangeSinceLast() {
          double retVal = 0.0;
          if (this.lastQuote != null) {
              double delta = this.currentQuote.getLastTrade() - this.lastQuote.getLastTrade();
              retVal = 100 * (delta / this.lastQuote.getLastTrade());
             }
             return retVal;
      }
  
      public double getChangeSinceYesterday() {
          double delta = (this.currentQuote.getLastTrade() - this.currentQuote
              .getClose());
          return 100 * (delta / this.currentQuote.getClose());
  
      }
  
      public void playAppropriateAudio() {
          if ((this.getChangeSinceYesterday() &gt; 2)
              || (this.getChangeSinceLast() &gt; 0.5)) {
              audioPlayer.playHappyMusic();
      }
  
          if ((this.getChangeSinceYesterday() &lt; -2)
              || (this.getChangeSinceLast() &lt; -0.5)) {
              audioPlayer.playSadMusic();
          }
      }
  
  }
  </code></pre>