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 17package vogar.android; 18 19import com.google.common.base.Joiner; 20import com.google.common.base.Supplier; 21import java.io.File; 22import java.io.IOException; 23import junit.framework.AssertionFailedError; 24import org.junit.Before; 25import org.junit.Rule; 26import org.mockito.Mock; 27import vogar.Action; 28import vogar.Classpath; 29import vogar.Console; 30import vogar.HostFileCache; 31import vogar.Mode; 32import vogar.Run; 33import vogar.Target; 34import vogar.Vogar; 35import vogar.commands.Mkdir; 36import vogar.commands.Rm; 37import vogar.commands.VmCommandBuilder; 38 39/** 40 * Base class for tests of {@link Mode} implementations. 41 */ 42public 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 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 90 protected abstract Target createTarget(); 91 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