title: PowerMock AssertionError
body: <p>I have a problem with the below test. The FileUtil class is the class I want to test.</p>
  
  <pre><code>import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.commons.io.FilenameUtils;
  import static org.easymock.EasyMock.expect;
  import static org.powermock.api.easymock.PowerMock.mockStatic;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.powermock.api.easymock.PowerMock;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  import static org.junit.Assert.assertEquals;
  
  
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest({FileUtil.class, FilenameUtils.class})
    public class TestBeanTest {
  
  
    private Map&lt;String, String&gt; fileUrls = new HashMap&lt;&gt;();
    private final String contentType = "image/jpeg";
    private final String defaultName = "default";
  
  
    @Before
    public void setUp() {
  
    }
  
    @After
    public void tearDown() {
  
      fileUrls.clear();
    }
  
    @Test
    public void testSanitizeFilename(){
  
      fileUrls.put("", "");
      fileUrls.put(" ", " ");
      fileUrls.put("jpg", "jpg.jpeg");
  
  
      mockStatic(FilenameUtils.class);
  
      for(Map.Entry&lt;String, String&gt; entry : fileUrls.entrySet()){
          expect(FilenameUtils.getExtension(entry.getKey())).andReturn(entry.getValue().substring(entry.getValue().lastIndexOf(". ") + 2)).anyTimes();
          expect(FilenameUtils.getBaseName(entry.getKey())).andReturn(entry.getValue().substring(entry.getValue().lastIndexOf(".") + 1)).anyTimes();
  
          PowerMock.replay();
          String result = FileUtil.sanitizeFilename(entry.getKey(), defaultName, contentType);
          assertEquals(result, entry.getValue());
          PowerMock.verify();
      }
  
    }
  
  
    @Test(expected = MalformedURLException.class)
    public void testSanitizeProcessedFilename() throws MalformedURLException{
      fileUrls.put("http://www.test.com", "image.jpeg");
      fileUrls.put("http://www.test.com/", "image.jpeg");
  
  
      mockStatic(FilenameUtils.class);
  
      for(Map.Entry&lt;String, String&gt; entry : fileUrls.entrySet()){
          String fileName = processUrl(entry.key());//throws MalformedURLException
  
          expect(FilenameUtils.getExtension(entry.getKey())).andReturn(entry.getValue().substring(entry.getValue().lastIndexOf(". ") + 2)).anyTimes();
          expect(FilenameUtils.getBaseName(entry.getKey())).andReturn(entry.getValue().substring(entry.getValue().lastIndexOf(".") + 1)).anyTimes();
  
          PowerMock.replay();
  
          String result = FileUtil.sanitizeFilename(fileName, defaultName, contentType);
          assertEquals(result, entry.getValue());
          PowerMock.verify();
      }
  
    }
  
    private String processUrl(String url){
      URL url = new URL(entry.getKey());
      String path = url.getPath();
      String fileName;
      int lastIndexOfSlash = path.lastIndexOf("/");
      if (lastIndexOfSlash &gt;= 0) {
              fileName = path.substring(lastIndexOfSlash + 1);
      } else {
              fileName = "";
      }
    }
  }
  </code></pre>
  
  <p>The first test method(testSanitizeFilename) is executed successfully, but the second one (testSanitizeProcessedFilename) throws the following error:</p>
  
  <pre><code>Expected exception: java.net.MalformedURLException
      java.lang.AssertionError
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:312)
  at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:88)
  at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:86)
  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
  at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)
  at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
  at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:104)
  at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
  at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
  at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
  at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
  at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
  at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
  at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
  at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
  at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
  </code></pre>
  
  <p>I'm not sure what I do wrong. I tried PowerMock.verifyAll() and PowerMock.replayAll(), but still got errors. Maybe it's wrong that I have the code in a loop? But I cannot figure another way to implement this. Any help will be appreciated.</p>