1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package vogar.android; 18 19 import com.google.common.base.Joiner; 20 import com.google.common.base.Supplier; 21 import java.io.File; 22 import java.io.IOException; 23 import junit.framework.AssertionFailedError; 24 import org.junit.Before; 25 import org.junit.Rule; 26 import org.mockito.Mock; 27 import vogar.Action; 28 import vogar.Classpath; 29 import vogar.Console; 30 import vogar.HostFileCache; 31 import vogar.Mode; 32 import vogar.Run; 33 import vogar.Target; 34 import vogar.Vogar; 35 import vogar.commands.Mkdir; 36 import vogar.commands.Rm; 37 import vogar.commands.VmCommandBuilder; 38 39 /** 40 * Base class for tests of {@link Mode} implementations. 41 */ 42 public abstract class AbstractModeTest { 43 44 @Rule 45 public VogarArgsRule vogarArgsRule = new VogarArgsRule(); 46 47 @Mock protected Console console; 48 49 protected Mkdir mkdir; 50 51 protected Rm rm; 52 53 protected AndroidSdk androidSdk; 54 55 protected Classpath classpath; 56 57 protected Run run; 58 59 protected Supplier<String> deviceUserNameSupplier = new Supplier<String>() { 60 @Override 61 public String get() { 62 return "fred"; 63 } 64 }; 65 66 @Before setUp()67 public void setUp() throws IOException { 68 mkdir = new Mkdir(console); 69 rm = new Rm(console); 70 71 androidSdk = new AndroidSdk(console, mkdir, 72 new File[] {new File("classpath")}, "android.jar", 73 new HostFileCache(console, mkdir)); 74 Target target = createTarget(); 75 76 final Vogar vogar = new Vogar(); 77 String[] args = vogarArgsRule.getTestSpecificArgs(); 78 if (!vogar.parseArgs(args)) { 79 throw new AssertionFailedError("Parse error in: " + Joiner.on(",").join(args) 80 + ". Please check stdout."); 81 } 82 83 run = new Run(vogar, false, console, mkdir, androidSdk, new Rm(console), target, 84 new File("runner/dir")); 85 86 classpath = new Classpath(); 87 classpath.addAll(new File("classes")); 88 } 89 createTarget()90 protected abstract Target createTarget(); 91 newVmCommandBuilder(Mode mode)92 protected VmCommandBuilder newVmCommandBuilder(Mode mode) { 93 Action action = new Action("action", "blah", new File("resources"), new File("source"), 94 new File("java")); 95 return mode.newVmCommandBuilder(action, new File("/work")); 96 } 97 } 98