//
// $Id$

package playn.java;

import org.junit.Test;
import static org.junit.Assert.*;

import playn.core.PlayN;
import playn.core.Log;
import playn.core.Image;
import playn.tests.AbstractPlayNTest;

/**
 * Tests various JavaImage behavior.
 */
public class JavaImageTest extends AbstractPlayNTest {

  @Test
  public void testMissingImage() {
    final StringBuilder buf = new StringBuilder();
    PlayN.log().setCollector(new Log.Collector() {
      public void logged(Log.Level level, String msg, Throwable cause) {
        buf.append(msg).append("\n");
      }
    });

    Image missing;
    try {
      missing = PlayN.assets().getImage("missing.png");
    } finally {
      PlayN.log().setCollector(null);
    }

    assertNotNull(missing);

    // ensure that width/height do not NPE
    missing.width();
    missing.height();

    // TODO: depending on the error text is somewhat fragile, but I want to be sure that a
    // reasonably appropriate error was logged
    String errlog = buf.toString();
    assertTrue(errlog.startsWith("Could not load image"));
    assertTrue(errlog.contains("missing.png"));

  }
}

@@ -638,16 +638,20 @@
 getImage
+Sync
 (%22missin
@@ -1031,16 +1031,80 @@
 e(errlog
+ + %22 must contain 'Could not load image'%22,%0A               errlog
 .startsW
@@ -1154,16 +1154,71 @@
 e(errlog
+ + %22 must contain 'missing.png'%22,%0A               errlog
 .contain
@@ -1236,15 +1236,14 @@
 png%22));%0A
-%0A
   %7D%0A%7D%0A

Load the missing image synchronously, improve assert error messages.