package com.github.bluelink8888.test;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.github.bluelink8888.translate.TokenImpl;

public class TranslateTest {
  
  
  private TokenImpl tokenImpl;
  
  
  @Before
  public void beforeTest(){
    try {
      tokenImpl = new TokenImpl();
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  
  @Test
  public void basicTest(){
    try {
      String token = tokenImpl.getToken("");
      System.out.println(token);
      Assert.assertNotNull(token);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
  @Test
  public void translateTest(){
    Assert.assertEquals("", "");
  }
  
}

@@ -51,75 +51,463 @@
 .io.
-IOException;%0A%0Aimport org.apache.http.client.ClientProtocolException
+BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLEncoder;%0A%0Aimport org.apache.http.HttpEntity;%0Aimport org.apache.http.HttpResponse;%0Aimport org.apache.http.HttpStatus;%0Aimport org.apache.http.client.ClientProtocolException;%0Aimport org.apache.http.client.HttpClient;%0Aimport org.apache.http.client.methods.HttpGet;%0Aimport org.apache.http.impl.client.HttpClientBuilder
 ;%0Aim
@@ -1198,36 +1198,1321 @@
     
-Assert.assertEquals(%22%22, %22%22);
+%0A    String target = %22no problem%22;%0A    String googleUrl = %22%22;%0A    try %7B%0A      googleUrl = %22https://translate.google.com.tw/translate_a/single?%22%0A          + %22client=t&sl=en&tl=zh-TW&hl=zh-TW%22%0A          + %22&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t%22%0A          + %22&ie=UTF-8&oe=UTF-8%22%0A          + %22&swap=1&source=btn&ssel=5&tsel=5&kc=0%22%0A          + %22&tk=%22 + tokenImpl.getToken(target) + %22&q=%22 + URLEncoder.encode(target, %22UTF-8%22);%0A    %7D catch (UnsupportedEncodingException e1) %7B%0A      e1.printStackTrace();%0A    %7D%0A%0A    HttpClient client = HttpClientBuilder.create().build();%0A    HttpGet req = new HttpGet(googleUrl);%0A%0A    try %7B%0A      HttpResponse resp = client.execute(req);%0A      resp.addHeader(%22Content-Type%22, %22application/json; charset=UTF-8%22);%0A      if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) %7B%0A        HttpEntity entity = resp.getEntity();%0A        BufferedReader bf = new BufferedReader(new InputStreamReader(%0A            entity.getContent()));%0A        StringBuffer sb = new StringBuffer();%0A        String line = %22%22;%0A        while ((line = bf.readLine()) != null) %7B%0A          sb.append(line);%0A        %7D%0A        System.out.println(sb.toString());%0A      %7Delse%7B%0A        System.out.println(%22failure%22);%0A      %7D%0A    %7D catch (Exception e) %7B%0A      e.printStackTrace();%0A    %7D%0A    %0A    
 %0A  %7D

add translate test