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.Language; 32 import vogar.Mode; 33 import vogar.Run; 34 import vogar.Target; 35 import vogar.Vogar; 36 import vogar.commands.Mkdir; 37 import vogar.commands.Rm; 38 import vogar.commands.VmCommandBuilder; 39 40 /** 41 * Base class for tests of {@link Mode} implementations. 42 */ 43 public abstract class AbstractModeTest { 44 45 @Rule 46 public VogarArgsRule vogarArgsRule = new VogarArgsRule(); 47 48 @Mock protected Console console; 49 50 protected Mkdir mkdir; 51 52 protected Rm rm; 53 54 protected AndroidSdk androidSdk; 55 56 protected Classpath classpath; 57 58 protected Run run; 59 60 protected Supplier<String> deviceUserNameSupplier = new Supplier<String>() { 61 @Override 62 public String get() { 63 return "fred"; 64 } 65 }; 66 67 @Before setUp()68 public void setUp() throws IOException { 69 mkdir = new Mkdir(console); 70 rm = new Rm(console); 71 72 androidSdk = new AndroidSdk(console, mkdir, 73 new File[] {new File("classpath")}, "android.jar", "desugar.jar", 74 new HostFileCache(console, mkdir), 75 Language.CUR); 76 Target target = createTarget(); 77 78 final Vogar vogar = new Vogar(); 79 String[] args = vogarArgsRule.getTestSpecificArgs(); 80 if (!vogar.parseArgs(args)) { 81 throw new AssertionFailedError("Parse error in: " + Joiner.on(",").join(args) 82 + ". Please check stdout."); 83 } 84 85 run = new Run(vogar, false, console, mkdir, androidSdk, new Rm(console), target, 86 new File("runner/dir")); 87 88 classpath = new Classpath(); 89 classpath.addAll(new File("classes")); 90 } 91 createTarget()92 protected abstract Target createTarget(); 93 newVmCommandBuilder(Mode mode)94 protected VmCommandBuilder newVmCommandBuilder(Mode mode) { 95 Action action = new Action("action", "blah", new File("resources"), new File("source"), 96 new File("java")); 97 return mode.newVmCommandBuilder(action, new File("/work")); 98 } 99 } 100