Android Open Source - WeatherBar Open Weather Test






From Project

Back to project page WeatherBar.

License

The source code is released under:

MIT License

If you think the Android project WeatherBar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cjbarker.wb.ws;
//  w w w  . ja  va2  s  . c o m
import java.lang.reflect.Method;

import com.cjbarker.wb.ws.OpenWeather;
import com.cjbarker.wb.ws.Weather.Forecast;

import junit.framework.TestCase;

public class OpenWeatherTest extends TestCase {
 
  private static final String TEST_JSON = "{\"coord\":{\"lon\":-97.74,\"lat\":30.27},\"sys\":{\"message\":0.0088,\"country\":\"United States of America\",\"sunrise\":1388842087,\"sunset\":1388879064},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"Sky is Clear\",\"icon\":\"01n\"}],\"base\":\"cmc stations\",\"main\":{\"temp\":48.94,\"pressure\":1022,\"temp_min\":46,\"temp_max\":52,\"humidity\":44},\"wind\":{\"speed\":1.1,\"gust\":2.57,\"deg\":145},\"clouds\":{\"all\":0},\"dt\":1388794341,\"id\":4671654,\"name\":\"Austin\",\"cod\":200}";
  
  private OpenWeather opWeather;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        this.opWeather = new OpenWeather();
    }
    
    public void testApiSet() {
      assertEquals(OpenWeather.ATX_API_URL, opWeather.getApiUrl());  
    }
    
    public void testParse() {
    try {
      Class cls = OpenWeather.class;
      Object obj = cls.newInstance();
      
      Class[] paramString = new Class[1];  
      paramString[0] = String.class;
      
      Method method = cls.getDeclaredMethod("parse", paramString);
      method.setAccessible(true);
      Forecast forecast = (Forecast)method.invoke(obj, TEST_JSON);
      
      assertNotNull(forecast);
      assertNotNull(forecast.temperature);
    } 
    catch (Exception e) {
      fail(e.getMessage());
    }
    }
}




Java Source Code List

com.cjbarker.wb.Main.java
com.cjbarker.wb.Notifier.java
com.cjbarker.wb.Prefs.java
com.cjbarker.wb.Util.java
com.cjbarker.wb.receiver.BatteryLevel.java
com.cjbarker.wb.receiver.Connection.java
com.cjbarker.wb.receiver.Screen.java
com.cjbarker.wb.ws.ClientRequestTest.java
com.cjbarker.wb.ws.ClientRequest.java
com.cjbarker.wb.ws.ClientResponse.java
com.cjbarker.wb.ws.OpenWeatherTest.java
com.cjbarker.wb.ws.OpenWeather.java
com.cjbarker.wb.ws.WeatherTest.java
com.cjbarker.wb.ws.Weather.java