content: /*
   * Copyright (C) 2016 david.wei (lighters)
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.lighters.demos.junit;
  
  import java.io.File;
  import java.io.IOException;
  import org.junit.Assert;
  import org.junit.Rule;
  import org.junit.Test;
  import org.junit.rules.ExpectedException;
  import org.junit.rules.TemporaryFolder;
  
  /**
   * Created by david on 16/9/7.
   * Email: huangdiv5@gmail.com
   * GitHub: https://github.com/alighters
   */
  public class RuleTest {
  
      @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
  
      @Rule public ExpectedException exception = ExpectedException.none();
  
      @Test
      public void countsAssets() throws IOException {
          File icon = tempFolder.newFile("icon.png");
          File assets = tempFolder.newFolder("assets");
          createAssets(assets, 3);
      }
  
      private void createAssets(File assets, int numberOfAssets) throws IOException {
          for (int index = 0; index < numberOfAssets; index++) {
              File asset = new File(assets, String.format("asset-%d.mpg", index));
              Assert.assertTrue("Asset couldn't be created.", asset.createNewFile());
          }
      }
  
      @Test
      public void throwsIllegalArgumentExceptionIfIconIsNull() {
          exception.expect(NullPointerException.class);
          throw new NullPointerException();
      }
  }
  